From 9473c836792d7fb32e25ad61407f6fd1e20d35f1 Mon Sep 17 00:00:00 2001 From: LandaMm Date: Wed, 21 May 2025 21:17:55 +0200 Subject: [PATCH] feat: hash utility --- internal/util/hash.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 internal/util/hash.go diff --git a/internal/util/hash.go b/internal/util/hash.go new file mode 100644 index 0000000..3ac20f4 --- /dev/null +++ b/internal/util/hash.go @@ -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 +}