1. 程式人生 > >spring securtty學習 (三)圖片驗證碼認證

spring securtty學習 (三)圖片驗證碼認證

log pri -s localdate 登陸 對象 ng- frame con

圖片驗證碼,在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

spring securtty學習 (三)圖片驗證碼認證