added: password hash

This commit is contained in:
nquidox 2025-07-07 11:42:54 +03:00
parent 12cf796d69
commit f5162fcd66
2 changed files with 17 additions and 0 deletions

15
pkg/utils/password.go Normal file
View file

@ -0,0 +1,15 @@
package utils
import "golang.org/x/crypto/bcrypt"
func (u *Utils) HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
if err != nil {
return "", err
}
return string(bytes), nil
}
func (u *Utils) ComparePasswords(hashedPassword string, plainPassword string) error {
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(plainPassword))
}