spring-security-site-docs-5.3.3.RELEASE-reference中5.1.2. Password Storage的一个说明

26 篇文章 0 订阅

这几天在看这个spring-security参考文档,有一个地方就是看不太明白,今天看明白了,所以单独列出来一段供有缘人阅读。

Password Matching 章节下面的有一个Getting Started Experience 这段的原文是:

Getting Started Experience

If you are putting together a demo or a sample, it is a bit cumbersome to take time to hash the passwords of your users. There are convenience mechanisms to make this easier, but this is still not intended for production.

Example 23. withDefaultPasswordEncoder Example

User user = User.withDefaultPasswordEncoder()

.username("user")

.password("password")

.roles("user")

.build();

System.out.println(user.getPassword()); // {bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG

我一直没有明白这到底是在做什么,我今天搞明白作者的意思了。

知识背景是:你的密码在数据库中现在都是存的都是编码后的,即某个密码假设是password,那么它在数据库里面啊存的实际是:{bcrypt}$2a$10$dXJ3SW6G7P50lGmMkkmwe.20cQQubK3.HZWzG3YB1tlRy.fqvM/BG 然后你在用的时候取的是这个被加密过后的字符串,前面{}是编码方法的id。这样依赖我们就明白作者的意思了:

他的意思是说呀:

If you are putting together a demo or a sample, it is a bit cumbersome to take time to hash the passwords of your users. There are convenience mechanisms to make this easier, but this is still not intended for production.

如果你打算做要给demo或者是例子,hash这个你的用户的password 是有点烦人繁琐的,我这有个法子就比较容易了,但是不推荐你在生产环境中这么搞。

demo的密码量肯定很少了,通过他提供的代码就可以很快地知道这个你提供的用户的密码了,然后你在数据库里面就存储这个加密后的字符串。然后再做验证,就是这么个意思。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值