{"record":{"id":"89e67524a1a4a9b1","repo":"wuyouzhuguli/SpringAll","slug":"error-89e675","errorCode":null,"errorMessage":"验证码不正确！","messagePattern":"验证码不正确！","errorType":"validation","errorClass":"ValidateCodeException","httpStatus":null,"severity":"warning","filePath":"61.Spring-security-Permission/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/61.Spring-security-Permission/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L40-L65","documentation":"Thrown when StringUtils.equalsIgnoreCase(codeInSession.getCode(), codeInRequest) is false: the submitted captcha text does not match the value stored in session. Comparison is case-insensitive, so only the actual digits/letters matter. The session attribute is removed after this check.","triggerScenarios":"User typed the wrong characters; the captcha image was misread (ambiguous 0/O, 1/I/l); the submitted value belongs to a different/older captcha image than the one in session.","commonSituations":"Hard-to-read generated image; user copy-pasted stale captcha; frontend displayed a cached image while the session held a newer code.","solutions":["Re-enter the captcha exactly as shown in the current image (case does not matter).","Refresh GET /code/image to get a new, clearer code and resubmit within the 60s window.","If the image is consistently unreadable, tweak createImageCode (font size, fewer干扰线, larger canvas) for legibility."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"// Basic sanity check before submit (length matches generated 4-digit code).\nconst code = form.get('imageCode');\nif (!/^\\d{4}$/.test(code || '')) { showFieldError('imageCode','请输入4位验证码'); return; }","typeGuard":null,"tryCatchPattern":"try { await login(); }\ncatch (e) {\n  if (/不正确/.test(e.message)) { await refreshCaptcha(); }\n  else handleError(e);\n}","preventionTips":["Refresh the image for a clearer code if unreadable.","Treat a mismatch as non-fatal: offer a fresh image rather than locking the user out.","Make generated digits more legible (fewer干扰线, larger font)."],"tags":["captcha","validation","spring-security","user-input"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}