wuyouzhuguli/SpringAll · warning · ValidateCodeException
验证码不正确!
Error message
验证码不正确!
What it means
ValidateCodeException from the 37.Spring-Security-RememberMe filter when the submitted imageCode does not equal the session code (case-insensitive). Prior checks passed, so this is a genuine value mismatch.
Source
Thrown at 37.Spring-Security-RememberMe/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java:58
filterChain.doFilter(httpServletRequest, httpServletResponse);
}
private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {
ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), "imageCode");
if (StringUtils.isBlank(codeInRequest)) {
throw new ValidateCodeException("验证码不能为空!");
}
if (codeInSession == null) {
throw new ValidateCodeException("验证码不存在!");
}
if (codeInSession.isExpire()) {
sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
throw new ValidateCodeException("验证码已过期!");
}
if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest)) {
throw new ValidateCodeException("验证码不正确!");
}
sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);
}
}
View on GitHub (pinned to 614d2578d9)
Solutions
- Re-enter the code exactly as shown, ignoring case.
- Refresh the captcha and retry.
- Trim the submitted value before comparing.
- Generate captchas from an unambiguous character set.
Example fix
// before
if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest)) {
throw new ValidateCodeException("验证码不正确!");
}
// after
String clean = StringUtils.trim(codeInRequest);
if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), clean)) {
throw new ValidateCodeException("验证码不正确,请刷新后重试!");
} Defensive patterns
Strategy: validation
Validate before calling
// normalize user input before submit
form.imageCode.value = form.imageCode.value.trim();
if (!form.imageCode.value) { showError('请输入图形验证码'); return; } Prevention
- Trim the captcha input before comparison.
- Use an unambiguous captcha character set.
- Offer a one-click refresh for misreads.
When it happens
Trigger: POST to login with a present, non-expired imageCode that differs from the rendered captcha.
Common situations: Misread ambiguous characters; stale autocomplete; refreshed image but typed old code; leading/trailing whitespace not trimmed.
Related errors
AI-assisted analysis of wuyouzhuguli/SpringAll@614d2578d9 (2026-08-14).
Data as JSON: /api/errors/83385e4c68bdb20b.
Report an issue: GitHub.