mirror of
https://github.com/1f349/tulip.git
synced 2024-11-15 00:01:45 +00:00
18 lines
445 B
Go
18 lines
445 B
Go
package utils
|
|
|
|
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))
|
|
}
|