{"record":{"id":"36b35564bb2a77f5","repo":"elunez/eladmin","slug":"logincodeenum","errorCode":null,"errorMessage":"验证码配置信息错误！正确配置查看 LoginCodeEnum ","messagePattern":"验证码配置信息错误！正确配置查看 LoginCodeEnum ","errorType":"exception","errorClass":"BadRequestException","httpStatus":400,"severity":"error","filePath":"eladmin-system/src/main/java/me/zhengjie/modules/security/config/CaptchaConfig.java","lineNumber":106,"sourceCode":"                break;\n            case CHINESE:\n                captcha = new ChineseCaptcha(width, height);\n                captcha.setLen(length);\n                break;\n            case CHINESE_GIF:\n                captcha = new ChineseGifCaptcha(width, height);\n                captcha.setLen(length);\n                break;\n            case GIF:\n                captcha = new GifCaptcha(width, height);\n                captcha.setLen(length);\n                break;\n            case SPEC:\n                captcha = new SpecCaptcha(width, height);\n                captcha.setLen(length);\n                break;\n            default:\n                throw new BadRequestException(\"验证码配置信息错误！正确配置查看 LoginCodeEnum \");\n        }\n        if(StringUtils.isNotBlank(fontName)){\n            captcha.setFont(new Font(fontName, Font.PLAIN, fontSize));\n        }\n        return captcha;\n    }\n\n    static class FixedArithmeticCaptcha extends ArithmeticCaptcha {\n        public FixedArithmeticCaptcha(int width, int height) {\n            super(width, height);\n        }\n\n        @Override\n        protected char[] alphas() {\n            // 生成随机数字和运算符\n            int n1 = num(1, 10), n2 = num(1, 10);\n            int opt = num(3);\n","sourceCodeStart":88,"sourceCodeEnd":124,"githubUrl":"https://github.com/elunez/eladmin/blob/55fbf705956949697dbd68bf9003776609d3d029/eladmin-system/src/main/java/me/zhengjie/modules/security/config/CaptchaConfig.java#L88-L124","documentation":"CaptchaConfig builds the captcha instance from the login.code.type property via a switch over LoginCodeEnum (arith, chinese, chinese-gif, gif, spec). Reaching the default branch — i.e. a configured type matching none of the enumerated values — throws BadRequestException '验证码配置信息错误！正确配置查看 LoginCodeEnum'. This fails at captcha-request time, so login cannot even reach the code check.","triggerScenarios":"Setting login.code.type in application.yml (or via -Dlogin.code.type) to an unrecognized value such as 'png', 'number', or a typo like 'chines-gif', then opening the login page /auth/code.","commonSituations":"Upgrading eladmin versions where LoginCodeEnum values changed and old configs linger; hand-editing yml with a value copied from a different captcha library; profile-specific yml overriding the type with an invalid string.","solutions":["Set login.code.type to one of the exact LoginCodeEnum values: arith / chinese / chinese-gif / gif / spec (check the enum source for your version).","Search all active profiles (application-dev.yml, prod, env vars, command line) for overriding login.code.type values.","After fixing, restart — captcha config is read at request time but the correct enum must be in place before users load the login page."],"exampleFix":"# before (application.yml)\nlogin:\n  code:\n    type: png   # not in LoginCodeEnum -> default branch throws\n# after\nlogin:\n  code:\n    type: arith","handlingStrategy":"validation","validationCode":"// fail fast at startup instead of at first captcha request\n@Value(\"${login.code.type}\") String type;\n@PostConstruct void check() {\n    try { LoginCodeEnum.valueOf(type.trim()); }\n    catch (IllegalArgumentException e) { throw new IllegalStateException(\"login.code.type 无效: \" + type); }\n}","typeGuard":"boolean isValidCaptchaType(String t) {\n    if (t == null) return false;\n    try { LoginCodeEnum.valueOf(t.trim()); return true; }\n    catch (IllegalArgumentException e) { return false; }\n}","tryCatchPattern":null,"preventionTips":["Copy captcha type values verbatim from LoginCodeEnum for your eladmin version.","Grep all profiles and env vars for login.code.type overrides after upgrading.","Add a startup assertion (validation above) so misconfigurations surface at boot, not on the login page."],"tags":["captcha","config","security","login"],"backgroundTag":null,"analyzedSha":"55fbf705956949697dbd68bf9003776609d3d029","analyzedAt":"2026-08-14T11:56:12.758Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}