mirror of
https://github.com/bjdgyc/anylink.git
synced 2025-08-08 15:56:43 +08:00
@@ -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()
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user