There is no PasswordEncoder mapped for the id "null" || Encoded password does not look like BCryp

本文介绍了Spring Security 5.0版本后密码加密机制的变化及常见错误ThereisnoPasswordEncodermappedfortheidnull的原因与解决办法。讨论了如何在配置类中正确设置密码编码器。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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”))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值