yinbangzhong
2024-07-29 9f78e3b126b15a9b331c3a1a318da1ceea30114c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package util
 
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
}