-
-
Save maddyonline/f29d8f7611e9c8367423975d99c9a771 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