Spring Security 报There is no PasswordEncoder mapped for the id "null"

本文介绍如何在Spring Security 5中配置BCrypt密码加密器,并演示了具体的实现代码。通过设置PasswordEncoder,确保应用程序的安全性。

查了下发现是spring security 版本在5.0后就要加个PasswordEncoder了


在securityConfig类下加入密码加密,在数据库中存的密码也是要经过这个加密的才能

@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
    auth.userDetailsService(userService()).passwordEncoder(new BCryptPasswordEncoder());
}

关于加密方法

public static void main(String[] args) {
    BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
    //对"123456"加密
    String encode = bCryptPasswordEncoder.encode("123456");
    System.out.println(encode); //结果:$10$/3Ow1Sy1r/SZSNTsRTCUIO0QI1qfjk.m.J7GyDOs/BcuObL4SXLG6 }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值