pushbits/authentication/credentials/credentials.go
2020-07-26 00:32:13 +02:00

21 lines
572 B
Go

package credentials
import "golang.org/x/crypto/bcrypt"
// CreatePassword returns a hashed version of the given password.
// TODO: Make strength configurable.
func CreatePassword(pw string) []byte {
strength := 12
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(pw), strength)
if err != nil {
panic(err)
}
return hashedPassword
}
// ComparePassword compares a hashed password with its possible plaintext equivalent.
func ComparePassword(hashedPassword, password []byte) bool {
return bcrypt.CompareHashAndPassword(hashedPassword, password) == nil
}