2021年2月28日 星期日

Default Password Encoder in Spring Security 5

https://www.baeldung.com/spring-security-5-default-password-encoder

org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder


ref:
https://openhome.cc/Gossip/Spring/SpringSecurity.html

從 Spring Security 5 開始,強制必須對密碼進行編碼,具體而言,方式之一就是直接指定 PasswordEncoder,在這邊使用的是 BCryptPasswordEncoder,並透過 encode 對密碼編碼,實際上這會是在使用者註冊時進行這動作,不過這邊先暫且寫在設定檔裡。

BCryptPasswordEncoder 實作了 bcrypt 加密演算法,是 Spring 官方推薦的加密方式,它會使用一個加鹽的流程以防禦彩虹表攻擊,就算是相同的密碼,因為每次產生的鹽值不同,編碼後的結果也就不會相同(鹽值會包含在編碼後的結果之中,不過 bcrypt 屬於 Slow Hash Function 手法,也就是破解它的時間成本高,高到可以讓攻擊者放棄)。

沒有留言:

張貼留言