如何使用Spring Security的新PasswordEncoder

因为Spring Security 3.1.4.RELEASE的,旧的org.springframework.security.authentication.encoding.PasswordEncoder 已被废弃的青睐org.springframework.security.crypto.password.PasswordEncoder。由于我的应用程序尚未公开发布,因此我决定使用新的,不建议使用的API。

到目前为止,我有一个ReflectionSaltSource自动使用用户的注册日期作为按用户盐注册的密码。

String encodedPassword = passwordEncoder.encodePassword(rawPassword, saltSource.getSalt(user));

在登录过程中,Spring还使用了我的bean来验证用户是否可以登录。我无法在新的密码编码器中实现此操作,因为SHA-1的默认实现- StandardPasswordEncoder仅具有添加全局密码的能力。编码器创建过程中的秘密盐。

有没有合理的方法可以使用未弃用的API进行设置?

回答:

如果你实际上尚未使用现有格式注册任何用户,那么最好改用BCrypt密码编码器。

这样就省了很多麻烦,因为你根本不必担心盐问题-细节完全封装在编码器中。使用BCrypt比使用普通哈希算法更强大,它也是与使用其他语言的应用程序兼容的标准。

确实没有理由为新应用程序选择任何其他选项。

以上是 如何使用Spring Security的新PasswordEncoder 的全部内容, 来源链接: utcz.com/qa/419028.html

回到顶部