🐛修复初始化超管密码bug
All checks were successful
continuous-integration/drone/tag Build is passing

This commit is contained in:
coward 2024-05-09 10:30:46 +08:00
parent 8fb39958d2
commit 76470fa71b
2 changed files with 11 additions and 3 deletions

View File

@ -79,7 +79,7 @@ func (s Script) CreateSuperAdmin() error {
Name: "超牛管理员", Name: "超牛管理员",
Account: "Admin", Account: "Admin",
Email: "", Email: "",
Password: utils.Password().GenerateHashPassword("admin123"), Password: "admin123",
IsAdmin: constant.SuperAdmin, IsAdmin: constant.SuperAdmin,
Status: constant.Normal, Status: constant.Normal,
}); err != nil { }); err != nil {

View File

@ -1,6 +1,9 @@
package utils package utils
import "golang.org/x/crypto/bcrypt" import (
"gitee.ltd/lxh/logger/log"
"golang.org/x/crypto/bcrypt"
)
type password struct{} type password struct{}
@ -26,5 +29,10 @@ func (password) GenerateHashPassword(pass string) string {
// @param pass // @param pass
// @return bool // @return bool
func (password) ComparePassword(dbPass, pass string) bool { func (password) ComparePassword(dbPass, pass string) bool {
return bcrypt.CompareHashAndPassword([]byte(dbPass), []byte(pass)) == nil if err := bcrypt.CompareHashAndPassword([]byte(dbPass), []byte(pass)); err != nil {
log.Errorf("密码错误: %v", err.Error())
return false
}
return true
} }