[精讚] [會員登入]
555

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

隨機好文

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

Arrays.asList 後想再add出現 UnsupportedOperationException 這個問題真是搞死我了 List<String> fruits = Arrays.asList("a

題庫批次匯入google表單 請先建一新試算表, 將題目轉成格式如下 並將網址列記下來, 後續的題目就是從此試算表讀出 題目 答案 選項一 選項二 選

Google sheet 建立成績單的總分及排名並提供名字下拉查詢 Google sheet, sum, rank, pull down list

[scratch] 將角色物件放到清單中,並依序讀出每個角色的X值 將角色物件放到清單中,並依序讀出每個角色的X值