mirror of
https://github.com/skyle1995/NetworkAuth.git
synced 2026-05-25 02:24:05 +08:00
调整日志和鉴权接管方案
This commit is contained in:
38
utils/captcha.go
Normal file
38
utils/captcha.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"github.com/mojocn/base64Captcha"
|
||||
)
|
||||
|
||||
// CaptchaStore 全局验证码存储器
|
||||
// 使用 base64Captcha 提供的默认内存存储,确保 admin 和 user 端可以共享验证码状态
|
||||
var CaptchaStore = base64Captcha.DefaultMemStore
|
||||
|
||||
// VerifyCaptcha 验证验证码的有效性
|
||||
// captchaId: 验证码的唯一标识符
|
||||
// captchaValue: 用户输入的验证码内容
|
||||
// 返回值: 验证是否通过
|
||||
// 该函数提供函数级注释,支持大小写不敏感匹配,验证通过后会自动删除验证码
|
||||
func VerifyCaptcha(captchaId, captchaValue string) bool {
|
||||
if captchaId == "" || captchaValue == "" {
|
||||
return false
|
||||
}
|
||||
|
||||
// 使用 switch 进行连续逻辑判断,尝试不同的大小写组合
|
||||
switch {
|
||||
case CaptchaStore.Verify(captchaId, captchaValue, true):
|
||||
// 原始值匹配成功
|
||||
return true
|
||||
case CaptchaStore.Verify(captchaId, strings.ToLower(captchaValue), true):
|
||||
// 小写匹配成功
|
||||
return true
|
||||
case CaptchaStore.Verify(captchaId, strings.ToUpper(captchaValue), true):
|
||||
// 大写匹配成功
|
||||
return true
|
||||
default:
|
||||
// 匹配失败
|
||||
return false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user