码迷,mamicode.com
首页 > 编程语言 > 详细

SpringSecurity出现org.springframework.security.authentication.BadCredentialsException: Bad credentials

时间:2020-01-27 09:30:00      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:return   new   stat   string   coder   信息   问题   get   一个   

出现Bad credentials,排除了配置问题,debug跟到了数据库的内容可以查出;

最后发现是因为直接通过insert语句增加了用户信息,密码没有经过加密。

一:springSecurity提供了一个增加{noop}字符串来解决

"{noop}"+userInfo.getPassword()
(但是没卵用。。。。)
二:
通过调用加密算法,重新把密码加密后再保存,就可以正常登陆了。
public class BCryptPasswordEncoderUtils {

private static BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
public static String encodePassword(String password){
return bCryptPasswordEncoder.encode(password);
}

public static void main(String[] args) {
String password = "demo";
String pwd = encodePassword(password);
System.out.println(pwd);
}
}

SpringSecurity出现org.springframework.security.authentication.BadCredentialsException: Bad credentials

标签:return   new   stat   string   coder   信息   问题   get   一个   

原文地址:https://www.cnblogs.com/herojava/p/12235262.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!