homebox/backend/pkgs/hasher/password.go

14 lines
345 B
Go
Raw Normal View History

2022-08-30 02:30:36 +00:00
package hasher
import "golang.org/x/crypto/bcrypt"
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), 14)
return string(bytes), err
}
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}