diff --git a/script/script.go b/script/script.go index 672ca55..195c8ac 100644 --- a/script/script.go +++ b/script/script.go @@ -79,7 +79,7 @@ func (s Script) CreateSuperAdmin() error { Name: "超牛管理员", Account: "Admin", Email: "", - Password: utils.Password().GenerateHashPassword("admin123"), + Password: "admin123", IsAdmin: constant.SuperAdmin, Status: constant.Normal, }); err != nil { diff --git a/utils/password.go b/utils/password.go index 547990a..dea42f4 100644 --- a/utils/password.go +++ b/utils/password.go @@ -1,6 +1,9 @@ package utils -import "golang.org/x/crypto/bcrypt" +import ( + "gitee.ltd/lxh/logger/log" + "golang.org/x/crypto/bcrypt" +) type password struct{} @@ -26,5 +29,10 @@ func (password) GenerateHashPassword(pass string) string { // @param pass // @return 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 }