[精讚] [會員登入]
426

spring security 使用MD5 hash 認證

spring security 預設使用BCrypt , 但是舊的系統使用md5 hash, @Bean Passwor

分享此文連結 //n.sfs.tw/16295

分享連結 spring security 使用MD5 hash 認證@igogo
(文章歡迎轉載,務必尊重版權註明連結來源)
最後編修
2024-01-03 14:47:40 By igogo
 

 

spring security 預設使用BCrypt , 但是舊的系統使用md5 hash,

 

 

 @Bean
    PasswordEncoder passwordEncoder() {
        PasswordEncoder defaults = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        Map<String, PasswordEncoder> encoderMap = new HashMap<>();
        encoderMap.put("MD5", new MessageDigestPasswordEncoder("MD5"));
        DelegatingPasswordEncoder delegatingPasswordEncoder = new DelegatingPasswordEncoder("MD5", encoderMap);
        delegatingPasswordEncoder.setDefaultPasswordEncoderForMatches(defaults);
        return delegatingPasswordEncoder;
    }

 

 

String rawPassword = "123456";
String oldMd5Passwd = String.format("{MD5}%s","e10adc3949ba59abbe56e057f20f883e");

String newMd5Passwd = passwordEncoder.encode(rawPassword);

logger.info(String.valueOf(passwordEncoder.matches(rawPassword,oldMd5Passwd)));

 

原資料庫裡經md5的密碼欄位要加上{MD5}

以密碼123456為例,  要存成  "{MD5}e10adc3949ba59abbe56e057f20f883e"

記得要存成小寫, 這裡卡關很久

 

 

https://emn178.github.io/online-tools/md5.html

https://www.cnblogs.com/cycheng/p/13984640.html

 

 

 

 

 

END

你可能感興趣的文章

spring boot 3 建立 Basic Authentication 參考以下網站, 建立一個http basic authentication 為例 https://www.geeksfo

download a file from spring boot controllers ownload a file from spring boot controllers

spring security 使用MD5 hash 認證 spring security 預設使用BCrypt , 但是舊的系統使用md5 hash, @Bean Passwor

我有話要說

>>

限制:留言最高字數1000字。 限制:未登入訪客,每則留言間隔需超過10分鐘,每日最多5則留言。

訪客留言

[無留言]

隨機好文

python 的RE python re

將google試算表當作簡易資料庫,利用Google apps cript 在網頁上操作查詢 將google試算表當作簡易資料庫,利用apps cript 在網頁上操作查詢 若我有一試算表資料 縣市 status

對照mac address 批次更改電腦名稱 讀取mac address 對照表, 還原電腦後,自動更改密碼 'show logged on user Dim

用java讀取microbit寫到serial的資料 用java讀取microbit寫到serial的資料

word題目轉google測驗 word題目轉google測驗