Golang create hash from []string

Hi guys! I am back! I have really big problem right now. I have this code

func Login(w http.ResponseWriter, r *http.Request) {
		r.ParseForm()
		mysql_login(r.Form["username"], r.Form["password"])
}
func mysql_login(username []string, password []string) bool {

	h := sha256.New()
	h.Write([]byte(password))
	hash := h.Sum(nil)


	err := mysqlconnection.QueryRow("SELECT username,password FROM users where username = ?", 2).Scan(&username, &password)
	if err != nil {
		panic(err.Error())
		return false
	} else {
		return true
	}
}

i am trying to make a sha256 hash from password []string, but it wont work.
i get this error:

cannot convert password (type []string) to type []byte

is there anyway how to create the hash?

It looks like your trying to convert a slice of strings to a byte slice instead of a plain string. Can you use string as your parameters in mysql_login instead of []string?

I have a fix.
Just simply replace

r.Form["password"]

with

r.FormValue("password")

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