{"record":{"id":"cc230107a0c74cff","repo":"wuyouzhuguli/SpringAll","slug":"error-cc2301","errorCode":null,"errorMessage":"验证码不正确！","messagePattern":"验证码不正确！","errorType":"validation","errorClass":"ValidateCodeException","httpStatus":null,"severity":"warning","filePath":"60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java","lineNumber":58,"sourceCode":"        filterChain.doFilter(httpServletRequest, httpServletResponse);\n    }\n\n    private void validateCode(ServletWebRequest servletWebRequest) throws ServletRequestBindingException {\n        ImageCode codeInSession = (ImageCode) sessionStrategy.getAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n        String codeInRequest = ServletRequestUtils.getStringParameter(servletWebRequest.getRequest(), \"imageCode\");\n\n        if (StringUtils.isBlank(codeInRequest)) {\n            throw new ValidateCodeException(\"验证码不能为空！\");\n        }\n        if (codeInSession == null) {\n            throw new ValidateCodeException(\"验证码不存在！\");\n        }\n        if (codeInSession.isExpire()) {\n            sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n            throw new ValidateCodeException(\"验证码已过期！\");\n        }\n        if (!StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest)) {\n            throw new ValidateCodeException(\"验证码不正确！\");\n        }\n        sessionStrategy.removeAttribute(servletWebRequest, ValidateController.SESSION_KEY_IMAGE_CODE);\n\n    }\n\n}\n","sourceCodeStart":40,"sourceCodeEnd":65,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/60.Spring-Security-Logout/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L40-L65","documentation":"Thrown by ValidateCodeFilter.validateCode (Logout project) when the submitted imageCode does not case-insensitively match the session code (the mismatch gate). The consumed code is removed from session afterward.","triggerScenarios":"User mistyped the captcha; stale captcha image displayed after a refresh; OCR/case differences.","commonSituations":"Ambiguous generated digits; mismatched displayed vs. stored code; whitespace differences.","solutions":["Re-type the code exactly and reload a fresh image.","Submit the raw displayed code without divergent trimming.","Refresh the captcha before resubmitting.","Tune generateCode for readability if mismatches are frequent."],"exampleFix":"// before\nformData.append(\"imageCode\", userGuess);\n\n// after\nrefreshCaptcha().then(() => formData.append(\"imageCode\", exactDisplayedCode));","handlingStrategy":"validation","validationCode":"// client-side: trim and validate 4-digit code\nconst code = (form.get('imageCode') || '').trim();\nif (!/^\\d{4}$/.test(code)) { showError('验证码格式不正确'); return; }","typeGuard":null,"tryCatchPattern":"// AuthenticationFailureHandler: on mismatch, refresh image and retry.","preventionTips":["Refresh the image before retrying.","Submit the exact displayed code.","Improve captcha legibility if needed."],"tags":["spring-security","captcha","validation","java"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}