MCPcopy Create free account
hub / github.com/aa12gq/goxenith / CheckAnswer

Method CheckAnswer

pkg/verifycode/verifycode.go:59–71  ·  view source on GitHub ↗

CheckAnswer 检查用户提交的验证码是否正确,key 可以是手机号或者 Email

(key string, answer string)

Source from the content-addressed store, hash-verified

57
58// CheckAnswer 检查用户提交的验证码是否正确,key 可以是手机号或者 Email
59func (vc *VerifyCode) CheckAnswer(key string, answer string) bool {
60
61 logger.DebugJSON("验证码", "检查验证码", map[string]string{key: answer})
62
63 // 方便开发,在非生产环境下,具备特殊前缀的手机号和 Email后缀,会直接验证成功
64 if !app.IsProduction() &&
65 (strings.HasSuffix(key, config.GetString("verifycode.debug_email_suffix")) ||
66 strings.HasPrefix(key, config.GetString("verifycode.debug_phone_prefix"))) || config.GetString("verifycode.debug_code") == answer {
67 return true
68 }
69
70 return vc.Store.Verify(key, answer, false)
71}
72
73// generateVerifyCode 生成验证码,并放置于 Redis 中
74func (vc *VerifyCode) generateVerifyCode(key string) string {

Callers 1

ValidateVerifyCodeFunction · 0.80

Calls 4

DebugJSONFunction · 0.92
IsProductionFunction · 0.92
GetStringFunction · 0.92
VerifyMethod · 0.65

Tested by

no test coverage detected