【发布时间】:2013-08-18 20:48:26
【问题描述】:
当我为 dtb 创建新条目时,我理解 hash+salt 的概念。如果我有一些固定的盐字符串,实现它可能并不难,但是当我想使用例如用户的生日作为盐时怎么做?将该密码保存到数据库很容易,但是如何在登录期间对其进行哈希处理?我在我的applicationContext-security.xml 文件中搜索了这段代码,他们在其中使用username 值作为盐:
<!-- authentication from database -->
<security:authentication-manager>
<security:authentication-provider>
<security:jdbc-user-service
data-source-ref="dataSource"
users-by-username-query="
select username,password, enabled
from users where username=?"authorities-by-username-query="
select u.username, ur.authority from users u, user_roles ur
where u.user_id = ur.user_id and u.username =? " />
<security:password-encoder hash="sha-256">
<security:salt-source user-property="username" />
</security:password-encoder-->
</security:authentication-provider>
</security:authentication-manager>
所以,如果我理解正确,这意味着,如果我想将用户的生日用作盐,我必须将其存储在我的 dtb 中,将其从 dtb 中取出,然后将其用作盐?这对我来说没有意义,因为如果我的users 表列中有username、password、birthday,那么可以对密码进行哈希处理,但对于可能的攻击者来说很清楚, birthday 值将用作盐。有什么我遗漏的东西还是真的有用吗?
【问题讨论】:
-
BCrypt 这样的东西是近来的首选。加盐是内部完成的,不用担心,更安全。
标签: java security spring-security salt password-hash