mica-captcha 验证码

验证码效果

captcha-001
captcha-002
captcha-003

依赖坐标

Maven

<dependency>
<groupId>net.dreamlu</groupId>
<artifactId>mica-captcha</artifactId>
<version>${mica.version}</version>
</dependency>

Gradle

implementation "net.dreamlu:mica-captcha"

配置项

配置项 默认值 说明
mica.captcha.cache-name micaCaptchaCache 验证码cache名,默认:micaCaptchaCache
mica.captcha.cookie-name mica-captcha 验证码cookie名,默认:mica-captcha
mica.captcha.enabled true 是否开启验证码,默认:true.

使用

Servlet

生成验证码

@Autowired
private MicaCaptchaServlet micaCaptcha;

/**
* 图形验证码
*/
@GetMapping(value = "/captcha.jpg", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public ResponseEntity<Resource> captcha(HttpServletResponse response) {
return micaCaptcha.generate(response);
}

校验验证码

boolean validated = micaCaptcha.validate(response, userInputCaptcha);

WebFlux

生成验证码

@Autowired
private MicaCaptchaReactive micaCaptcha;

/**
* 图形验证码
*/
@GetMapping(value = "/captcha.jpg", produces = MediaType.IMAGE_JPEG_VALUE)
@ResponseBody
public Mono<ResponseEntity<Resource>> captcha(ServerWebExchange exchange) {
return Mono.just(micaCaptcha.generate(exchange));
}

校验验证码

boolean validated = micaCaptcha.validate(exchange, userInputCaptcha);

生成其他类型验证码

  • micaCaptcha.generateBase64 生成 base64 图片验证码。
  • micaCaptcha.validateBase64 校验 base64 图片验证码。

微信公众号

如梦技术

精彩内容每日推荐!!!