19 lines
602 B
Go
19 lines
602 B
Go
// Package auth provides password hashing and session handling for WhereWoof.
|
|
package auth
|
|
|
|
import "golang.org/x/crypto/bcrypt"
|
|
|
|
// HashPassword returns a bcrypt hash of the given plaintext password.
|
|
func HashPassword(password string) (string, error) {
|
|
b, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return string(b), nil
|
|
}
|
|
|
|
// CheckPassword reports whether the plaintext password matches the bcrypt hash.
|
|
func CheckPassword(hash, password string) bool {
|
|
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
|
|
}
|