最开始学习shiro的时候需要自己保存User的salt, 最近系统升级,使用了Shiro1.3发现在1.2的时候Shiro提供了新的DefaultPasswordService来简化Password encode/match工作。很好奇为啥不在需要自己保存User的salt,查看了defaultpasswordservice的源代码,发现了其中的奥秘,具体看Shiro的代码(关注*部分),主要是重新构建Hash,然后从Hash中获取salt来做提交密码的hash,比较计算出来的hash和存储hash是否一致。
public boolean More ...passwordsMatch(Object submittedPlaintext, String saved) {
ByteSource plaintextBytes = createByteSource(submittedPlaintext);
if (saved == null || saved.length() == 0) {
return plaintextBytes == null || plaintextBytes.isEmpty();
} else {
if (plaintextBytes == null

本文探讨了Shiro 1.2引入的DefaultPasswordService如何简化密码编码和匹配工作,揭示了不再需要手动保存User salt的原因。通过分析源代码,特别是关注的*部分,展示了DefaultPasswordService如何从Hash中获取salt进行密码验证。
最低0.47元/天 解锁文章
2323

被折叠的 条评论
为什么被折叠?



