EasyCaptcha Java Captcha Library – Features, Integration, and Usage Guide
This article introduces EasyCaptcha, a Java graphic captcha library supporting GIF, Chinese characters, and arithmetic types, explains how to integrate it via Maven, demonstrates usage in SpringBoot with controller and HTML snippets, and provides demo links and a concise summary for developers.
EasyCaptcha is a Java graphic captcha library that supports GIF, Chinese characters, arithmetic types and can be used in Java Web, Java SE and other projects.
It offers rich visual effects as shown in the screenshots.
To add the library via Maven, include the following dependency:
<dependencies>
<dependency>
<groupId>com.github.whvcse</groupId>
<artifactId>easy-captcha</artifactId>
<version>1.6.2</version>
</dependency>
</dependencies>In a SpringBoot application, you can create a controller to output the captcha image:
@Controller
public class CaptchaController {
@RequestMapping("/captcha")
public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
CaptchaUtil.out(request, response);
}
}On the front end, embed the captcha image with an <img> tag pointing to the "/captcha" endpoint: <img src="/captcha" width="130px" height="48px" /> To verify the captcha during login, use CaptchaUtil.ver and clear the session if verification fails:
@Controller
public class LoginController {
@PostMapping("/login")
public JsonResult login(String username, String password, String verCode) {
if (!CaptchaUtil.ver(verCode, request)) {
CaptchaUtil.clear(request); // clear session captcha
return JsonResult.error("验证码不正确");
}
// ... other login logic ...
}
}The source code is available at https://gitee.com/whvse/EasyCaptcha .
Demo screenshots and a live demo are provided at https://tools.cloudbed.vip .
In summary, EasyCaptcha is extremely easy to use, offers a variety of captcha types, supports multiple integration methods, and is recommended for developers seeking a quick and flexible captcha solution.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
IT Xianyu
We share common IT technologies (Java, Web, SQL, etc.) and practical applications of emerging software development techniques. New articles are posted daily. Follow IT Xianyu to stay ahead in tech. The IT Xianyu series is being regularly updated.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
