图片验证码,在spring security 学习(二)用户认证自定义上添加。
具体步骤相对来说简单分为三步:生成图片验证码、显示给用户输入,登陆认证中加入校验验证码;
添加验证依赖
<!-- 验证码 --><dependency> <groupId>org.springframework.social</groupId> <artifactId>spring-social-config</artifactId></dependency>
定义图片对象ImageCode:属性有图片、验证码,过期时间
public class ImageCode { private BufferedImage img; private String code; private LocalDateTime exTime; public ImageCode(BufferedImage img, String code, int expireIn) { this.img= img; this.code = code; this.exTime= LocalDateTime.now().plusSeconds(expireIn); } public ImageCode(BufferedImage img, String code, LocalDateTime exTime) { this.img= img; this.code = code; this.exTime= exTime; }
生成验证码图片输出到客户端,并保存到session
原文地址:https://www.cnblogs.com/yuiqng/p/10587312.html
时间: 2024-10-12 08:49:50