$ go get -u golang.org/x/crypto/bcrypt
package main
import (
"fmt"
"golang.org/x/crypto/bcrypt"
)
func main() {
password := "nilpointer"
bytes, _ := bcrypt.GenerateFromPassword([]byte(password), 14)
hash := string(bytes)
fmt.Println("hash: ", hash)
password2 := "nilpointer"
if bcrypt.CompareHashAndPassword([]byte(hash), []byte(password2)) == nil {
fmt.Println("password and password 2 match")
} else {
fmt.Println("password and password 2 do not match")
}
}
hash: $2a$14$ImTW84puxXsIoCa3Vx6o5uo8FBCAMvrAvw/z/WR7EvbiQu9XQo6Te
password and password 2 match