From a49bd6d127aed39c2f116eea9e4af10f6b8d6913 Mon Sep 17 00:00:00 2001 From: Tsln Date: Thu, 4 Mar 2021 21:53:37 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=AE=97=E6=9C=AF=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B=E9=AA=8C=E8=AF=81=E7=A0=81=E5=9C=A8=20Java=2015+=20?= =?UTF-8?q?=E7=9A=84=E5=85=BC=E5=AE=B9=E9=97=AE=E9=A2=98=20(#607)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit cdbc3a8faaf5958489758608329aa70095b37bb3) --- .../security/config/bean/LoginProperties.java | 25 ++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java index ca57213a..b13f173e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/config/bean/LoginProperties.java @@ -80,7 +80,7 @@ public class LoginProperties { switch (loginCode.getCodeType()) { case arithmetic: // 算术类型 https://gitee.com/whvse/EasyCaptcha - captcha = new ArithmeticCaptcha(loginCode.getWidth(), loginCode.getHeight()); + captcha = new FixedArithmeticCaptcha(loginCode.getWidth(), loginCode.getHeight()); // 几位数运算,默认是两位 captcha.setLen(loginCode.getLength()); break; @@ -109,4 +109,27 @@ public class LoginProperties { } 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); + + // 计算结果 + int res = new int[]{n1 + n2, n1 - n2, n1 * n2}[opt]; + // 转换为字符运算符 + char optChar = "+-x".charAt(opt); + + this.setArithmeticString(String.format("%s%c%s=?", n1, optChar, n2)); + this.chars = String.valueOf(res); + + return chars.toCharArray(); + } + } }