tulip/password/password.go

18 lines
448 B
Go
Raw Normal View History

2023-09-06 22:20:09 +01:00
package password
2023-09-29 16:37:23 +01:00
import (
"golang.org/x/crypto/bcrypt"
)
2023-09-06 22:20:09 +01:00
2023-09-29 16:37:23 +01:00
// HashString is used to represent a string containing a password hash
type HashString string
func HashPassword(password string) (HashString, error) {
2023-09-06 22:20:09 +01:00
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
2023-09-29 16:37:23 +01:00
return HashString(bytes), err
2023-09-06 22:20:09 +01:00
}
2023-09-29 16:37:23 +01:00
func CheckPasswordHash(hash HashString, password string) error {
2023-09-06 22:20:09 +01:00
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
}