Created
January 11, 2021 20:25
-
-
Save somersbmatthews/953bc008dd97fd714cdce31fcadb90fe to your computer and use it in GitHub Desktop.
bcrypt hashing functions #bcrypt #go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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