spring securtty学习 (三)图片验证码认证 spring security 学习(二)用户认证自定义

图片验证码,在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

猜你喜欢

转载自www.cnblogs.com/yuiqng/p/10587312.html