gvNIX典型安全性:建议如何将salt添加到密码中

时间:2015-09-15 17:30:46

标签: spring-roo gvnix

我正在使用Spring Roo和gvNIX典型的安全性(Spring安全性)。这很棒!谢谢制作人!

使用典型安全性为密码哈希添加salt的最佳方法是什么?

2 个答案:

答案 0 :(得分:2)

尝试使用org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder作为建议Spring Security documentation

  

始终使用单向密码哈希算法,例如bcrypt,它使用内置的salt值,该值对于每个存储的密码都不同

为此,请按照以下步骤操作:

  1. 修改applicationContext-security.xml文件以更改messageDigestPasswordEncoder定义,如下所示:

    <beans:bean 
        class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" 
        id="messageDigestPasswordEncoder"/>
    
  2. 修改MessageDigestPasswordEncoder

  3. 代码中BCryptPasswordEncoder的所有引用
  4. BCryptPasswordEncoder.matches方法替换任何字符串比较密码验证。 UserController.create中的示例:

    // Replace
    //
    // if(!savedUser.getPassword().equals(user.getPassword())){
    //
    // by
    if(!messageDigestPasswordEncoder.matches(
             user.getPassword(), savedUser.getPassword())){     
    
  5. 使用messageDigestPasswordEncoder.encode在DB上存储密码。

  6. 这未经过测试但应该有效。

    祝你好运!

答案 1 :(得分:0)

你是英雄!

一个小小的补充

<beans:bean class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"
    id="bCryptPasswordEncoder">
    <beans:constructor-arg name="strength" value="11" />
</beans:bean>

而不是原来的

<beans:constructor-arg value="sha-256"/>

将此标准添加到Typical Security插件是不是一个想法?