api/pkg/utils/password.go

16 lines
421 B
Go
Raw Permalink Normal View History

2025-07-07 11:42:54 +03:00
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))
}