SpringBoot整合Security登录报错 There is no PasswordEncoder mapped for the id "null"
2019-04-14 10:59
676 查看
Spring Security中密码的存储格式是“{id}…………”。前面的id是加密方式,id可以是bcrypt、sha256等,后面跟着的是加密后的密码。也就是说,程序拿到传过来的密码的时候,会首先查找被“{”和“}”包括起来的id,来确定后面的密码是被怎么样加密的,如果找不到就认为id是null。这也就是为什么我们的程序会报错:There is no PasswordEncoder mapped for the id “null”。官方文档举的例子中是各种加密方式针对同一密码加密后的存储形式,原始密码都是“password”。
如果是从内存中取出密码的话,需要在config中改一下代码
@Override protected void configure(AuthenticationManagerBuilder auth) throws Exception { auth.inMemoryAuthentication().passwordEncoder(new BCryptPasswordEncoder()) .withUser("user1").password(new BCryptPasswordEncoder().encode("123")).roles("role1","role2","role3") .and().withUser("user2").password(new BCryptPasswordEncoder().encode("123")).roles("role2") .and().withUser("user3").password(new BCryptPasswordEncoder().encode("123")).roles("role3"); }
如果你用的是在数据库中存储用户名和密码,那么一般是要在用户注册时就使用BCrypt编码将用户密码加密处理后存储在数据库中。并且修改configure()方法,加入".passwordEncoder(new BCryptPasswordEncoder())",保证用户登录时使用bcrypt对密码进行处理再与数据库中的密码比对.
本文参考https://docs.spring.io/spring-security/site/docs/5.1.5.RELEASE/reference/htmlsingle/
相关文章推荐
- There is no PasswordEncoder mapped for the id "null"
- Spring Security 无法登陆,报错:There is no PasswordEncoder mapped for the id “null” 问题里的坑
- Spring Security 无法登陆,报错:There is no PasswordEncoder mapped for the id “null”
- There is no PasswordEncoder mapped for the id "null"
- sruts2.1整合spring3.0抛出异常: Status 404 - There is no Action mapped for namespace /jsp and action name
- There is no Action mapped for namespace [/] and action name [repassword] associated with context pat
- SSM整合 错误收集之 There is no Action mapped for namespace / and action[unknown location]
- 异常分析:There is no Action mapped for action name null. - [unknown location]
- ssh整合中遇到There is no Action mapped for namespace [/] and action name [] associated with context path
- SSH + Oracle 整合问题之六 There is no Action mapped for namespace / and action name open.
- [Struts2与spring集成]There is no Action mapped for action name index. - [unknown location]
- 使用struts2框架后servlet不能正常访问的解决方案 There is no Action mapped for action name null
- ssh整合DWR的时候报 HTTP Status 404 - There is no Action mapped for namespace / and action name bookInfo.
- Spring整合Shiro出现There is no session with id [XXX] with root cause问题的解决方案
- org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'readRoomID'
- Struts2提示:There is no Action mapped for namespace [/] and action的解决办法
- Struts2 无法导向到首页There is no Action mapped for namespace / and action name
- There is no Action mapped for namespace / and action name 问题的解决办法
- There is no Action mapped for namespace [/]
- Struts2中关于"There is no Action mapped for namespace / and action name"的总结