{"record":{"id":"b3ab91b7c2f1a135","repo":"wuyouzhuguli/SpringAll","slug":"error-b3ab91","errorCode":null,"errorMessage":"验证码不能为空！","messagePattern":"验证码不能为空！","errorType":"exception","errorClass":"ValidateCodeException","httpStatus":null,"severity":"warning","filePath":"37.Spring-Security-RememberMe/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java","lineNumber":48,"sourceCode":"    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {\n        if (StringUtils.equalsIgnoreCase(\"/login\", httpServletRequest.getRequestURI())\n                && StringUtils.equalsIgnoreCase(httpServletRequest.getMethod(), \"post\")) {\n            try {\n                validateCode(new ServletWebRequest(httpServletRequest));\n            } catch (ValidateCodeException e) {\n                authenticationFailureHandler.onAuthenticationFailure(httpServletRequest, httpServletResponse, e);\n                return;\n            }\n        }\n        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","sourceCodeStart":30,"sourceCodeEnd":64,"githubUrl":"https://github.com/wuyouzhuguli/SpringAll/blob/614d2578d9495acf53cc02f2dee9c6131cc5e51a/37.Spring-Security-RememberMe/src/main/java/cc/mrbird/validate/code/ValidateCodeFilter.java#L30-L64","documentation":"Identical ValidateCodeException logic to the other modules, here in the 37.Spring-Security-RememberMe image-captcha filter. This branch fires when the submitted imageCode request parameter is null or blank. The filter routes the exception to authenticationFailureHandler, blocking the login/remember-me flow.","triggerScenarios":"POST to the login URL in the RememberMe demo with the imageCode form field missing, empty, or whitespace-only.","commonSituations":"Login form omits the imageCode input (common when remember-me was bolted onto an older form); field name attribute is not 'imageCode'; test client does not send imageCode.","solutions":["Add <input type=\"text\" name=\"imageCode\"> to the login form and submit a non-empty value.","Confirm the request parameter name matches the filter's getStringParameter(...,\"imageCode\").","Add client-side required-field validation before submit.","In tests, always include a non-empty imageCode parameter."],"exampleFix":"// before\n<input name=\"username\"/>\n<input name=\"password\"/>\n<input type=\"checkbox\" name=\"remember-me\"/>\n<!-- imageCode field missing -->\n\n// after\n<input name=\"username\"/>\n<input name=\"password\"/>\n<input type=\"text\" name=\"imageCode\" required/>\n<input type=\"checkbox\" name=\"remember-me\"/>","handlingStrategy":"validation","validationCode":"// front-end guard before submitting the remember-me login form\nif (!form.imageCode || form.imageCode.trim() === '') {\n    showError('请输入图形验证码');\n    return;\n}\nform.submit();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When adding remember-me to an existing form, re-verify the captcha field is still present and named 'imageCode'.","Mark the captcha input required and disable submit until filled.","Include a non-empty imageCode in every login integration test."],"tags":["spring-security","captcha","validation","remember-me","form"],"backgroundTag":null,"analyzedSha":"614d2578d9495acf53cc02f2dee9c6131cc5e51a","analyzedAt":"2026-08-14T04:40:03.488Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}