25 lines
653 B
Go
25 lines
653 B
Go
|
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
|
||
|
}
|