:tada:初步完成用户

This commit is contained in:
coward
2024-10-18 17:19:19 +08:00
commit f375118c88
45 changed files with 3302 additions and 0 deletions

38
utils/password.go Normal file
View File

@@ -0,0 +1,38 @@
package utils
import (
"gitee.ltd/lxh/logger/log"
"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 {
if err := bcrypt.CompareHashAndPassword([]byte(dbPass), []byte(pass)); err != nil {
log.Errorf("密码错误: %v", err.Error())
return false
}
return true
}