tulip/utils/password.go
2024-01-29 10:44:45 +00:00

18 lines
445 B
Go

package utils
import (
"golang.org/x/crypto/bcrypt"
)
// HashString is used to represent a string containing a password hash
type HashString string
func HashPassword(password string) (HashString, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return HashString(bytes), err
}
func CheckPasswordHash(hash HashString, password string) error {
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
}