feat: hash utility

This commit is contained in:
2025-05-21 21:17:55 +02:00
parent 0b8c03e8c5
commit 9473c83679

15
internal/util/hash.go Normal file
View File

@ -0,0 +1,15 @@
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
}