mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-03 18:22:57 +00:00
19 lines
513 B
Go
19 lines
513 B
Go
package utils
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// HashPassword hashes a password using bcrypt
|
|
func HashPassword(password string) (string, error) {
|
|
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
return string(hashedPassword), nil
|
|
}
|
|
|
|
// CheckPassword verifies a password against a hash
|
|
func CheckPassword(password, hashedPassword string) error {
|
|
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
|
|
}
|