Files

18 lines
428 B
Go
Raw Permalink Normal View History

package utils
import (
"golang.org/x/crypto/bcrypt"
)
// HashPassword 密码哈希
func HashPassword(password string) (string, error) {
bytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(bytes), err
}
// CheckPasswordHash 验证密码
func CheckPasswordHash(password, hash string) bool {
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
return err == nil
}