shelldoor/servers/hash.go

25 lines
653 B
Go
Raw Normal View History

2024-09-28 19:26:08 +03:00
package servers
import "golang.org/x/crypto/bcrypt"
// The type represents login used to login.
type Login string
// The type represents passwords used to login.
type Password string
// The type represents hash of the password.
type PasswordHash string
// Simple hashing password function.
func HashPassword(password Password) (PasswordHash, error) {
bts, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return PasswordHash(bts), err
}
// Check for password to match the hash.
func PasswordMatchHash(password Password, hash PasswordHash) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}