[精讚] [會員登入]
36

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 security 使用MD5 hash 認證 spring security 預設使用BCrypt , 但是舊的系統使用md5 hash, @Bean Passwor

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

我有話要說

>>

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

訪客留言

[無留言]

隨機好文

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

00-F2 的 IPV6 反解設定 近日, 強者我的大神同事, line 傳來一句: igogo 上次你那個ipv6的設定檔 再幫我跑一次 如連結 程式都寫

hoc2018灑水機器人 灑水機器人的工作是替行道樹灑水,機器人的灑水範圍有限(左前方、左方、左後方),請寫程式控制機器 人判斷須灑水的狀況。每顆

windows ad 如何得知 dn 值 如何得知 windows ad 上的使用者dn 值 https://support.symantec.com/en_US

臺中市雲端校務系統與Windows AD帳號整合(3) LDAP的基本概念