diff --git a/database/db.go b/database/db.go index 9744d57e..c72d28cf 100644 --- a/database/db.go +++ b/database/db.go @@ -60,8 +60,8 @@ func initUser() error { } user := &model.User{ - Username: defaultUsername, - Password: hashedPassword, + Username: defaultUsername, + Password: hashedPassword, } return db.Create(user).Error } diff --git a/database/model/model.go b/database/model/model.go index 5c29d483..2e7095d3 100644 --- a/database/model/model.go +++ b/database/model/model.go @@ -21,9 +21,9 @@ const ( ) type User struct { - Id int `json:"id" gorm:"primaryKey;autoIncrement"` - Username string `json:"username"` - Password string `json:"password"` + Id int `json:"id" gorm:"primaryKey;autoIncrement"` + Username string `json:"username"` + Password string `json:"password"` } type Inbound struct { diff --git a/go.mod b/go.mod index 66ebce41..c9a61524 100644 --- a/go.mod +++ b/go.mod @@ -15,8 +15,10 @@ require ( github.com/robfig/cron/v3 v3.0.1 github.com/shirou/gopsutil/v4 v4.25.3 github.com/valyala/fasthttp v1.61.0 + github.com/xlzd/gotp v0.1.0 github.com/xtls/xray-core v1.250306.1-0.20250430044058-87ab8e512882 go.uber.org/atomic v1.11.0 + golang.org/x/crypto v0.37.0 golang.org/x/text v0.24.0 google.golang.org/grpc v1.72.0 gorm.io/driver/sqlite v1.5.7 @@ -78,14 +80,12 @@ require ( github.com/valyala/fastjson v1.6.4 // indirect github.com/vishvananda/netlink v1.3.0 // indirect github.com/vishvananda/netns v0.0.5 // indirect - github.com/xlzd/gotp v0.1.0 // indirect github.com/xtls/reality v0.0.0-20240909153216-e26ae2305463 // indirect github.com/yusufpapurcu/wmi v1.2.4 // indirect go.uber.org/automaxprocs v1.6.0 // indirect go.uber.org/mock v0.5.2 // indirect go4.org/netipx v0.0.0-20231129151722-fdeea329fbba // indirect golang.org/x/arch v0.16.0 // indirect - golang.org/x/crypto v0.37.0 // indirect golang.org/x/mod v0.24.0 // indirect golang.org/x/net v0.39.0 // indirect golang.org/x/sync v0.13.0 // indirect diff --git a/web/service/user.go b/web/service/user.go index 595b08e2..f0b04f52 100644 --- a/web/service/user.go +++ b/web/service/user.go @@ -8,8 +8,8 @@ import ( "x-ui/logger" "x-ui/util/crypto" - "gorm.io/gorm" "github.com/xlzd/gotp" + "gorm.io/gorm" ) type UserService struct { @@ -44,19 +44,19 @@ func (s *UserService) CheckUser(username string, password string, twoFactorCode logger.Warning("check user err:", err) return nil } - - if !crypto.CheckPasswordHash(user.Password, password) { + + if !crypto.CheckPasswordHash(user.Password, password) { return nil } - - twoFactorEnable, err := s.settingService.GetTwoFactorEnable(); + + twoFactorEnable, err := s.settingService.GetTwoFactorEnable() if err != nil { logger.Warning("check two factor err:", err) return nil } - + if twoFactorEnable { - twoFactorToken, err := s.settingService.GetTwoFactorToken(); + twoFactorToken, err := s.settingService.GetTwoFactorToken() if err != nil { logger.Warning("check two factor token err:", err)