Files
2025-09-23 21:17:19 +08:00

15 lines
400 B
Go

package utils
import "golang.org/x/crypto/bcrypt"
func PasswordBcryptHash(password string) string {
hash, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
OkOrPanic(err)
return string(hash)
}
// hash比较密码 相同为true不同为false
func PasswordCompare(password, hash string) bool {
return bcrypt.CompareHashAndPassword([]byte(hash), []byte(password)) == nil
}