gohorsejobs/backend/internal/utils/password.go
Tiago Yamamoto 1c7ef95c1a first commit
2025-12-09 19:04:48 -03:00

15 lines
477 B
Go
Executable file

package utils
import "golang.org/x/crypto/bcrypt"
// HashPassword generates a bcrypt hash from a plain password
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
// CheckPasswordHash compares a password with its hash
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}