mirror of
https://github.com/eduardolat/pgbackweb.git
synced 2026-05-18 10:38:26 -05:00
26 lines
606 B
Go
26 lines
606 B
Go
package cryptoutil
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"golang.org/x/crypto/bcrypt"
|
|
)
|
|
|
|
// CreateBcryptHash creates a bcrypt hash of the given password
|
|
func CreateBcryptHash(password string) (string, error) {
|
|
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(hash), nil
|
|
}
|
|
|
|
// VerifyBcryptHash verifies the given password against the bcrypt hash
|
|
func VerifyBcryptHash(password, hash string) error {
|
|
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
|
|
if err != nil {
|
|
return fmt.Errorf("invalid password")
|
|
}
|
|
return nil
|
|
}
|