Files
nbi_alarm/core/utils/bcrypt.go
2023-08-22 19:25:39 +08:00

15 lines
413 B
Go

package utils
import "golang.org/x/crypto/bcrypt"
// Encrypt 加密明文密码
func Encrypt(password string) (string, error) {
hashedBytes, err := bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost)
return string(hashedBytes), err
}
// Compare 密文校验
func Compare(hashedPassword, password string) error {
return bcrypt.CompareHashAndPassword([]byte(hashedPassword), []byte(password))
}