whycxzp
2023-10-23 5454894d1c9c0bb69ba016beb17b78b8cce4de72
中等级缺陷5-2
1个文件已修改
10 ■■■■ 已修改文件
src/main/java/com/whyc/controller/MessageController.java 10 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/main/java/com/whyc/controller/MessageController.java
@@ -8,6 +8,9 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
@RequestMapping("message")
@RestController
@Api(tags = "验证码")
@@ -15,11 +18,14 @@
    @ApiOperation("获取验证码")
    @GetMapping("/getFontDynamicCode")
    public Response getFontDynamicCode(){
    public Response getFontDynamicCode() throws NoSuchAlgorithmException {
        StringBuilder sb = new StringBuilder();
        String originStr = "0123456789abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ0123456789";
        SecureRandom random;
        random = SecureRandom.getInstance("SHA1PRNG");
        for (int i = 0; i < 4; i++) {
            sb.append(originStr.charAt((int) Math.round(Math.random()*(originStr.length()-1))));
            sb.append(originStr.charAt(random.nextInt(originStr.length())));
        }
        //内存Session中存储动态口令
        ActionUtil.getSession().setAttribute("fontDynamicCode", sb.toString());