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


出现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);
}
}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM