elunez/eladmin · error · BadRequestException

验证码配置信息错误!正确配置查看 LoginCodeEnum

Error message

验证码配置信息错误!正确配置查看 LoginCodeEnum 

What it means

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.

Source

Thrown at eladmin-system/src/main/java/me/zhengjie/modules/security/config/CaptchaConfig.java:106

                break;
            case CHINESE:
                captcha = new ChineseCaptcha(width, height);
                captcha.setLen(length);
                break;
            case CHINESE_GIF:
                captcha = new ChineseGifCaptcha(width, height);
                captcha.setLen(length);
                break;
            case GIF:
                captcha = new GifCaptcha(width, height);
                captcha.setLen(length);
                break;
            case SPEC:
                captcha = new SpecCaptcha(width, height);
                captcha.setLen(length);
                break;
            default:
                throw new BadRequestException("验证码配置信息错误!正确配置查看 LoginCodeEnum ");
        }
        if(StringUtils.isNotBlank(fontName)){
            captcha.setFont(new Font(fontName, Font.PLAIN, fontSize));
        }
        return captcha;
    }

    static class FixedArithmeticCaptcha extends ArithmeticCaptcha {
        public FixedArithmeticCaptcha(int width, int height) {
            super(width, height);
        }

        @Override
        protected char[] alphas() {
            // 生成随机数字和运算符
            int n1 = num(1, 10), n2 = num(1, 10);
            int opt = num(3);

View on GitHub (pinned to 55fbf70595)

Solutions

  1. Set login.code.type to one of the exact LoginCodeEnum values: arith / chinese / chinese-gif / gif / spec (check the enum source for your version).
  2. Search all active profiles (application-dev.yml, prod, env vars, command line) for overriding login.code.type values.
  3. After fixing, restart — captcha config is read at request time but the correct enum must be in place before users load the login page.

Example fix

# before (application.yml)
login:
  code:
    type: png   # not in LoginCodeEnum -> default branch throws
# after
login:
  code:
    type: arith
Defensive patterns

Strategy: validation

Validate before calling

// fail fast at startup instead of at first captcha request
@Value("${login.code.type}") String type;
@PostConstruct void check() {
    try { LoginCodeEnum.valueOf(type.trim()); }
    catch (IllegalArgumentException e) { throw new IllegalStateException("login.code.type 无效: " + type); }
}

Type guard

boolean isValidCaptchaType(String t) {
    if (t == null) return false;
    try { LoginCodeEnum.valueOf(t.trim()); return true; }
    catch (IllegalArgumentException e) { return false; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of elunez/eladmin@55fbf70595 (2026-08-14). Data as JSON: /api/errors/36b35564bb2a77f5. Report an issue: GitHub.