lavender/password/password.go

18 lines
448 B
Go
Raw Normal View History

2024-08-19 22:37:30 +01:00
package password
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))
}