Hash password compare

I try to compare db password and form value password then given following error.
crypto/bcrypt: hashedPassword is not the hash of the given password. i have attached the coding function

https://play.golang.org/p/Olq4APRNBDe

This code works fine
package main

import (
“fmt”
golang.org/x/crypto/bcrypt
)

func main() {
var err error

passwordRequest := "Testx"
passwordDB := "Test"

bsp,err := bcrypt.GenerateFromPassword([]byte(passwordDB),bcrypt.DefaultCost)	
if err != nil {
   panic(err)
}
err = bcrypt.CompareHashAndPassword(bsp,[]byte(passwordRequest))
if err != nil {
   panic(err)
} else {
   fmt.Println("password are equal")
}	

}

You can also try authentication directly from sql command, eg:

Of course, before that you must insert the encrypted password likewise.

Stay with bcrypt, SHA1 is very weak. Bcrypt also salts passwords by default.

thank you very much it’s working

Thanks George for your reply, I used Yamil’s code and it worked.

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