[精讚] [會員登入]
348

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

你可能感興趣的文章

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

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

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

[vue.js] 設定 content type 今天在wickt 端怎麼就是收不到vue.js 以post 傳過來的資料 找了好久才發現 application/jso

centos 7 移机出現 dracut-initqueue timeout centos 7 移机出現 dracut-initqueue timeout 處理

vue.js modal 作兩個選項按鈕並導向不同頁面 vue.js modal 作兩個選項按鈕

axios vuejs application/x-www-form-urlencoded 送資料 VUE.JS 以 application/x-www-form-urlencoded 送資料

[scratch2] 分數排名 在清單中隨机產生5名學生的考試分數, 再利用另一個清單排名 想法, 分數愈高者排名愈好, 例如名次是第5名, 那分數是最