Skip to content

Instantly share code, notes, and snippets.

@somersbmatthews
Created January 11, 2021 20:25
Show Gist options
  • Save somersbmatthews/953bc008dd97fd714cdce31fcadb90fe to your computer and use it in GitHub Desktop.
Save somersbmatthews/953bc008dd97fd714cdce31fcadb90fe to your computer and use it in GitHub Desktop.
bcrypt hashing functions #bcrypt #go
func hashAndSalt(pwd []byte) string {
hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
if err != nil {
log.Println(err)
}
return string(hash)
}
func comparePasswords(hashedPassword string, plainPassword []byte) bool {
byteHash := []byte(hashedPassword)
err := bcrypt.CompareHashAndPassword(byteHash, plainPassword)
if err != nil {
log.Println(err)
return false
}
return true
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment