wuyouzhuguli/SpringAll · warning · ValidateCodeException

验证码不正确!

Error message

验证码不正确!

What it means

ValidateCodeException from the image-captcha ValidateCodeFilter in module 38 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 38.Spring-Security-SmsCode/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

  1. Re-enter the code exactly as shown, ignoring case.
  2. Refresh the captcha and retry.
  3. Trim the submitted value before comparing.
  4. 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

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/c18c8cdc08998659. Report an issue: GitHub.