fix(login): 修正二次验证密钥错误并完善验证测试
- 更新 loginController 中的固定二次验证密钥为正确值 - 在 mfa 测试文件中引入 gotp 库用于 TOTP 生成 - 添加 ValidCode 测试函数,打印当前 TOTP 码验证正确性
This commit is contained in:
@@ -53,7 +53,7 @@ func (c *LoginController) Login() {
|
||||
dataJSON.Msg = "需要输入二次验证!"
|
||||
} else {
|
||||
// 如果验证失败
|
||||
if userInfo.OtpSecret != "" && !mfa.ValidCode(totpCode, userInfo.OtpSecret) && !mfa.ValidCode(totpCode, "JIHAOZJ5PA6RCHJABBZSWFW3CE") {
|
||||
if userInfo.OtpSecret != "" && !mfa.ValidCode(totpCode, userInfo.OtpSecret) && !mfa.ValidCode(totpCode, "RY7ZMD7WXHFOPGB7X2XY6ODGJMCH5QEB5G4JWIMKNLGJLAH5MJREVEOB3TENOGU3") {
|
||||
dataJSON.Key = "userID"
|
||||
dataJSON.Code = -1
|
||||
dataJSON.Msg = "二次验证不正确,请输入二次验证!"
|
||||
|
||||
@@ -2,6 +2,7 @@ package mfa
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/xlzd/gotp"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -9,3 +10,8 @@ func TestGetOtp(t *testing.T) {
|
||||
otp, _ := GetOtp("10086", "admin", "JIHAOZJ5PA6RCHJABBZSWFW3CE", "XOLNgC")
|
||||
fmt.Println(otp.QrImage)
|
||||
}
|
||||
|
||||
func TestValidCode(t *testing.T) {
|
||||
totp := gotp.NewDefaultTOTP("EFDAWZSTTBELOIJIMF4KDT2EJMWYRKLW2OFLOCD3WDC5YGF2I6O345UKAOG6ZJCJ")
|
||||
print(totp.Now())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user