Question : bcrypt golang
Answered by : restu-wahyu-saputra
package util
import ( "github.com/sirupsen/logrus" "golang.org/x/crypto/bcrypt"
)
func HashPassword(password string) string { pw := []byte(password) result, err := bcrypt.GenerateFromPassword(pw, bcrypt.DefaultCost) if err != nil { logrus.Fatal(err.Error()) } return string(result)
}
func ComparePassword(hashPassword string, password string) error { pw := []byte(password) hw := []byte(hashPassword) err := bcrypt.CompareHashAndPassword(hw, pw) return err
}
Source : https://stackoverflow.com/questions/23259586/bcrypt-password-hashing-in-golang-compatible-with-node-js | Last Update : Wed, 14 Apr 21