From 23bb379afe638d2e800c9ae7577b252fa3f11ad0 Mon Sep 17 00:00:00 2001 From: ssongliu Date: Fri, 10 Mar 2023 16:47:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20mfa=20=E4=BA=8C=E6=AC=A1=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=20bug=20=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/auth.go | 18 ++++++++----- frontend/src/lang/modules/en.ts | 1 + frontend/src/lang/modules/zh.ts | 1 + .../views/database/redis/setting/index.vue | 26 ++++++++++++++++--- frontend/src/views/host/monitor/index.vue | 5 +++- .../src/views/host/terminal/command/index.vue | 17 +++++++----- .../host/terminal/terminal/host-create.vue | 4 +-- .../src/views/login/components/login-form.vue | 11 +++++++- 8 files changed, 63 insertions(+), 20 deletions(-) diff --git a/backend/app/service/auth.go b/backend/app/service/auth.go index e9ec66b01..dc89b55e5 100644 --- a/backend/app/service/auth.go +++ b/backend/app/service/auth.go @@ -10,6 +10,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/encrypt" "github.com/1Panel-dev/1Panel/backend/utils/jwt" + "github.com/1Panel-dev/1Panel/backend/utils/mfa" "github.com/gin-gonic/gin" "github.com/pkg/errors" uuid "github.com/satori/go.uuid" @@ -68,11 +69,7 @@ func (u *AuthService) Login(c *gin.Context, info dto.Login) (*dto.UserLoginInfo, return nil, err } if mfa.Value == "enable" { - mfaSecret, err := settingRepo.Get(settingRepo.WithByKey("MFASecret")) - if err != nil { - return nil, err - } - return &dto.UserLoginInfo{Name: nameSetting.Value, MfaStatus: mfa.Value, MfaSecret: mfaSecret.Value}, nil + return &dto.UserLoginInfo{Name: nameSetting.Value, MfaStatus: mfa.Value}, nil } return u.generateSession(c, info.Name, info.AuthMethod) @@ -91,7 +88,16 @@ func (u *AuthService) MFALogin(c *gin.Context, info dto.MFALogin) (*dto.UserLogi if err != nil { return nil, constant.ErrAuth } - if info.Password != pass && nameSetting.Value == info.Name { + if info.Password != pass && nameSetting.Value != info.Name { + return nil, constant.ErrAuth + } + + mfaSecret, err := settingRepo.Get(settingRepo.WithByKey("MFASecret")) + if err != nil { + return nil, err + } + success := mfa.ValidCode(info.Code, mfaSecret.Value) + if !success { return nil, constant.ErrAuth } diff --git a/frontend/src/lang/modules/en.ts b/frontend/src/lang/modules/en.ts index eb6b47c4c..6822b38aa 100644 --- a/frontend/src/lang/modules/en.ts +++ b/frontend/src/lang/modules/en.ts @@ -105,6 +105,7 @@ export default { rePassword: 'Confirm Password', welcome: 'Welcome back, please enter your username and password to log in!', errorAuthInfo: 'The user name or password you entered is incorrect, please re-enter!', + errorMfaInfo: 'Incorrect authentication information, please try again!', captchaHelper: 'Please enter the verification code', errorCaptcha: 'Verification code error!', safeEntrance: 'Please use the correct entry to log in to the panel', diff --git a/frontend/src/lang/modules/zh.ts b/frontend/src/lang/modules/zh.ts index 3b206857b..9e48688ec 100644 --- a/frontend/src/lang/modules/zh.ts +++ b/frontend/src/lang/modules/zh.ts @@ -110,6 +110,7 @@ export default { rePassword: '确认密码', welcome: '欢迎回来,请输入用户名和密码登录!', errorAuthInfo: '您输入的用户名或密码不正确,请重新输入!', + errorMfaInfo: '错误的验证信息,请重试!', captchaHelper: '请输入验证码', errorCaptcha: '验证码错误!', safeEntrance: '请使用正确的入口登录面板', diff --git a/frontend/src/views/database/redis/setting/index.vue b/frontend/src/views/database/redis/setting/index.vue index 1242986ed..277ca4b21 100644 --- a/frontend/src/views/database/redis/setting/index.vue +++ b/frontend/src/views/database/redis/setting/index.vue @@ -46,6 +46,7 @@ theme="cobalt" :styleActiveLine="true" :extensions="extensions" + @ready="handleReady" v-model="redisConf" /> @@ -127,7 +128,7 @@