16 lines
478 B
Go
16 lines
478 B
Go
package util
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// HashPassword generates a bcrypt hash for the given password.
|
|
func HashPassword(password string) (string, error) {
|
|
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
|
|
return string(bytes), err
|
|
}
|
|
|
|
// VerifyPassword verifies if the given password matches the stored hash.
|
|
func VerifyPassword(password, hash string) bool {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
return err == nil
|
|
}
|