There is no PasswordEncoder mapped for the id "null" || Encoded password does not look like BCryp
There is no PasswordEncoder mapped for the id "null"
官方查阅spring security 5.0 版本后新增PasswordEncoder多种加密方式,也改变加密格式
-
现如今Spring Security中密码的存储格式是“{id}…………”。前面的id是加密方式,id可以是bcrypt、sha256等,后面跟着的是加密后的密码。也就是说,程序拿到传过来的密码的时候,会首先查找被“{”和“}”包括起来的id,来确定后面的密码是被怎么样加密的,如果找不到就认为id是null。这也就是为什么我们的程序会报错:There is no PasswordEncoder mapped for the id “null”。
-
解决方法
-
在配置类中WebSercurityConfig中修改
方式1:
方式2:
Encoded password does not look like BCryp
存入密码时需要对密码进行加密:
.password(passwordEncoder().encode(“password”))