mirror of
https://github.com/XShengTech/MEGREZ.git
synced 2026-01-14 00:57:17 +08:00
[Fix] 🐛 User Password Hash Error
This commit is contained in:
parent
6e2742614e
commit
ddc948d76c
@ -1,8 +1,10 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"megrez/libs/crypto"
|
||||
"megrez/services/config"
|
||||
"strconv"
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@ -24,7 +26,8 @@ type Users struct {
|
||||
}
|
||||
|
||||
func (u *Users) PasswordHash(password string) string {
|
||||
return crypto.Sha256(password + u.CreatedAt.GoString() + config.GetSystemSalt())
|
||||
fmt.Println(password, u.CreatedAt.UnixMicro(), config.GetSystemSalt())
|
||||
return crypto.Sha256(password + strconv.FormatInt(u.CreatedAt.UnixMicro(), 10) + config.GetSystemSalt())
|
||||
}
|
||||
|
||||
func (u *Users) CheckPassword(password string) bool {
|
||||
|
||||
@ -35,7 +35,6 @@ func registerHandler(ctx iris.Context) {
|
||||
Role: 0,
|
||||
Balance: 0,
|
||||
}
|
||||
user.Password = user.PasswordHash(userReq.Password)
|
||||
|
||||
if !config.GetSystemVerify() {
|
||||
user.Role = 1
|
||||
@ -48,5 +47,13 @@ func registerHandler(ctx iris.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
user.Password = user.PasswordHash(userReq.Password)
|
||||
result = database.DB.Save(&user)
|
||||
if result.Error != nil {
|
||||
l.Error("save user error: %v", result.Error)
|
||||
middleware.Error(ctx, middleware.CodeRegisterError, iris.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
middleware.Success(ctx)
|
||||
}
|
||||
|
||||
@ -23,12 +23,17 @@ func systemInit() (err error) {
|
||||
Email: "admin@gpuManager.com",
|
||||
Role: 3,
|
||||
}
|
||||
user.Password = user.PasswordHash("admin123456")
|
||||
result := database.DB.Create(&user)
|
||||
if result.Error != nil {
|
||||
l.Error("Create admin user failed, Error: %v", result.Error)
|
||||
return
|
||||
}
|
||||
user.Password = user.PasswordHash("admin123456")
|
||||
result = database.DB.Save(&user)
|
||||
if result.Error != nil {
|
||||
l.Error("Save admin user failed, Error: %v", result.Error)
|
||||
return
|
||||
}
|
||||
|
||||
l.Info("System init success")
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user