wireguard-dashboard/utils/password.go
2024-03-06 16:24:49 +08:00

31 lines
675 B
Go

package utils
import "golang.org/x/crypto/bcrypt"
type password struct{}
func Password() password {
return password{}
}
// GenerateHashPassword
// @description: 生成hash密码
// @receiver password
// @param pass
// @return string
func (password) GenerateHashPassword(pass string) string {
bytePass := []byte(pass)
hPass, _ := bcrypt.GenerateFromPassword(bytePass, bcrypt.DefaultCost)
return string(hPass)
}
// ComparePassword
// @description: 密码比对
// @receiver password
// @param dbPass
// @param pass
// @return bool
func (password) ComparePassword(dbPass, pass string) bool {
return bcrypt.CompareHashAndPassword([]byte(dbPass), []byte(pass)) == nil
}