This commit is contained in:
Looly
2020-09-17 11:26:14 +08:00
parent 6b89c841d3
commit 85601e2446
5 changed files with 32 additions and 29 deletions

View File

@@ -1,5 +1,6 @@
package cn.hutool.captcha.generator;
import cn.hutool.core.math.Calculator;
import cn.hutool.core.util.CharUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
@@ -59,20 +60,8 @@ public class MathGenerator implements CodeGenerator {
return false;
}
final int a = Integer.parseInt(StrUtil.sub(code, 0, this.numberLength).trim());
final char operator = code.charAt(this.numberLength);
final int b = Integer.parseInt(StrUtil.sub(code, this.numberLength + 1, this.numberLength + 1 + this.numberLength).trim());
switch (operator) {
case '+':
return (a + b) == result;
case '-':
return (a - b) == result;
case '*':
return (a * b) == result;
default:
return false;
}
final int calculateResult = (int) Calculator.conversion(code);
return result == calculateResult;
}
/**