mirror of
https://github.com/1f349/tulip.git
synced 2024-12-23 00:34:07 +00:00
18 lines
448 B
Go
18 lines
448 B
Go
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))
|
|
}
|