GitHub上一个超级简单 Java 图形验证码模块

设为“星标”,和你一起掌握更多数据库知识

简介

Java图形验证码,支持Gif、中文、算术等类型,可用于Java Web、JavaSE等项目。

效果展示

集成项目

maven方式引入:

<dependencies>
   <dependency>
      <groupId>com.github.whvcse</groupId>
      <artifactId>easy-captcha</artifactId>
      <version>1.6.2</version>
   </dependency>
</dependencies>

在 SpringBoot 中使用

@Controller
public class CaptchaController {

    @RequestMapping("/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        CaptchaUtil.out(request, response);
    }
}

前端html代码:

<img src="/captcha" width="130px" height="48px" />

判断验证码是否正确:

@Controller
public class LoginController {

    @PostMapping("/login")
    public JsonResult login(String username,String password,String verCode){
        if (!CaptchaUtil.ver(verCode, request)) {
            CaptchaUtil.clear(request);  // 清除session中的验证码
            return JsonResult.error("验证码不正确");
        }
    }   
}

源码:https://gitee.com/whvse/EasyCaptcha

演示

地址:https://tools.cloudbed.vip

小结

超级简单,种类丰富,支持多种接入方式,推荐给各位小伙伴!

(完)

设为“星标”,和你一起掌握更多数据库知识 简介 Java图形验证码,支持Gif、中文、算术等类型,可用于Java Web、JavaSE等项目。 效果展示 集成项目 maven方式引入:            com.github.whvcse        easy-captcha        1.6.2     在 SpringBoot 中使用 @Controller public class CaptchaController {     @RequestMapping("/captcha")     public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {         CaptchaUtil.out(request, response);     } } 前端html代码: 判断验证码是否正确: @Controller public class LoginController {     @PostMapping("/login")     public JsonResult login(String username,String password,String verCode){         if (!CaptchaUtil.ver(verCode, request)) {             CaptchaUtil.clear(request);  // 清除session中的验证码             return JsonResult.error("验证码不正确");         }     }    } 源码:https://gitee.com/whvse/EasyCaptcha 演示 地址:https://tools.cloudbed.vip 小结 超级简单,种类丰富,支持多种接入方式,推荐给各位小伙伴! (完)
经验分享 程序员 微信小程序 职场和发展