15 lines
400 B
Go
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
|
|
}
|