How can I store slice of bytes in mysql database

Hello, I want to store user’s password in my database I have encrypted it with ‘bcrypt’ packet and then converted into string and i guess this is awful way of storing data. So bcypte GenerateFromPassword method returns slice of bytes so how can i strore this value in my ‘mysql’ database. I also need to get this password soon for comparing with user’s input in login page.

I don’t know MySQL incredibly well (I personally use PostgreSQL 99% of the time) but you can store a string if you want. Just hex encode the byte slice into a string:

package main

import (
	"encoding/hex"
	"fmt"
)

func main() {
	data := []byte{123, 12, 13, 31}
	fmt.Println(hex.EncodeToString(data))
}

https://play.golang.org/p/0wc3SPnZD-A

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.