Merge pull request #339 from wsczx/dev

增加弹窗输入OTP动态码的功能
This commit is contained in:
bjdgyc
2024-10-08 18:25:09 +08:00
committed by GitHub
7 changed files with 292 additions and 72 deletions

View File

@@ -117,13 +117,13 @@ func checkLocalUser(name, pwd, group string) error {
}
// 判断otp信息
pinCode := pwd
if !v.DisableOtp {
pinCode = pwd[:pl-6]
otp := pwd[pl-6:]
if !checkOtp(name, otp, v.OtpSecret) {
return fmt.Errorf("%s %s", name, "动态码错误")
}
}
// if !v.DisableOtp {
// pinCode = pwd[:pl-6]
// otp := pwd[pl-6:]
// if !CheckOtp(name, otp, v.OtpSecret) {
// return fmt.Errorf("%s %s", name, "动态码错误")
// }
// }
// 判断用户密码
if pinCode != v.PinCode {
@@ -171,7 +171,7 @@ func init() {
}
// 判断令牌信息
func checkOtp(name, otp, secret string) bool {
func CheckOtp(name, otp, secret string) bool {
key := fmt.Sprintf("%s:%s", name, otp)
userOtpMux.Lock()

View File

@@ -4,7 +4,6 @@ import (
"testing"
"github.com/stretchr/testify/assert"
"github.com/xlzd/gotp"
)
func TestCheckUser(t *testing.T) {
@@ -30,10 +29,10 @@ func TestCheckUser(t *testing.T) {
ast.Nil(err)
// 验证 PinCode + OtpSecret
totp := gotp.NewDefaultTOTP(u.OtpSecret)
secret := totp.Now()
err = CheckUser("aaa", u.PinCode+secret, group)
ast.Nil(err)
// totp := gotp.NewDefaultTOTP(u.OtpSecret)
// secret := totp.Now()
// err = CheckUser("aaa", u.PinCode+secret, group)
// ast.Nil(err)
// 单独验证密码
u.DisableOtp = true