mirror of
https://github.com/pushbits/server.git
synced 2025-05-01 11:17:11 +02:00
20 lines
535 B
Go
20 lines
535 B
Go
package credentials
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// CreatePassword returns a hashed version of the given password.
|
|
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
|
|
}
|