|
|
@@ -1,7 +1,8 @@
|
|
|
package com.fdkankan.manage.controller;
|
|
|
|
|
|
-import cn.hutool.captcha.CaptchaUtil;
|
|
|
-import cn.hutool.captcha.LineCaptcha;
|
|
|
+import cn.hutool.captcha.*;
|
|
|
+import cn.hutool.captcha.generator.MathGenerator;
|
|
|
+import cn.hutool.captcha.generator.RandomGenerator;
|
|
|
import cn.hutool.extra.servlet.ServletUtil;
|
|
|
import com.dtflys.forest.annotation.BaseRequest;
|
|
|
import com.fdkankan.manage.common.RedisKeyUtil;
|
|
|
@@ -44,7 +45,9 @@ public class LoginController extends BaseController {
|
|
|
if(!redisUtil.hasKey(String.format(RedisKeyUtil.loginAuthCode,id))){
|
|
|
throw new BusinessException(ResultCode.LOGIN_AUTH_NOT_EXIST);
|
|
|
}
|
|
|
- if(!redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)).equals(param.getAuthCode())){
|
|
|
+ MathGenerator mathGenerator = new MathGenerator(3);
|
|
|
+ boolean verify = mathGenerator.verify(redisUtil.get(String.format(RedisKeyUtil.loginAuthCode,id)),param.getAuthCode());
|
|
|
+ if(!verify){
|
|
|
throw new BusinessException(ResultCode.LOGIN_AUTH_NOT_EXIST);
|
|
|
}
|
|
|
|
|
|
@@ -68,7 +71,9 @@ public class LoginController extends BaseController {
|
|
|
response.setContentType("image/jpeg");
|
|
|
String id = request.getSession().getId();
|
|
|
try {
|
|
|
- LineCaptcha lineCaptcha = CaptchaUtil.createLineCaptcha(200, 100,4,60);
|
|
|
+ LineCaptcha lineCaptcha = new LineCaptcha(400, 100);
|
|
|
+ MathGenerator mathGenerator = new MathGenerator(3);
|
|
|
+ lineCaptcha.setGenerator(mathGenerator);
|
|
|
redisUtil.set(String.format(RedisKeyUtil.loginAuthCode,id),lineCaptcha.getCode(),60*5);
|
|
|
lineCaptcha.write(response.getOutputStream());
|
|
|
response.getOutputStream().close();
|
|
|
@@ -78,4 +83,13 @@ public class LoginController extends BaseController {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public static void main(String[] args) {
|
|
|
+ LineCaptcha lineCaptcha = new LineCaptcha(400, 100);
|
|
|
+ MathGenerator mathGenerator = new MathGenerator(3);
|
|
|
+ boolean verify = mathGenerator.verify("79 *40 =","3160");
|
|
|
+ System.out.println(verify);
|
|
|
+
|
|
|
+ System.out.println(lineCaptcha.getCode());
|
|
|
+ }
|
|
|
+
|
|
|
}
|