我们使用bcrypt对用户的密码进行散列,并存储最后10个散列的列表,以确保用户在创建新密码时不会使用与最后10个相同的密码。
我们遇到的一个问题是,检查密码历史记录是一个非常缓慢的过程。算法如下所示:
// The user's entered password on the password change page
String rawPassword = ...
// For demonstration purposes, the password has passed all other validation measures
Boolean passwordIsValid = true;
// Loop through all the stored passwords we have for that user. We have a max of 10
for (String oldHashed: user.passwordHashHistory) {
// Must re-hash every time using the same salt as the one stored in history
// NOTE: SLLOOOWWWWW!
String newHashed = Bcrypt.hashPw(rawPassword, oldHashed);
// Now we can see if it's a match
if (newHashed.compareTo(oldHashed) == 0) {
// User is using one of the old passwords
passwordIsValid = false;
}
}上面的代码可以工作,但在我的工作站上可以花5-6秒来验证一个用户的密码是否被更改。除了减少日志访问或增强服务器之外,我还能做任何事情来缓解这种情况吗?
发布于 2014-11-20 17:08:48
BCrypt算法的设计非常慢,成本因素可以确定计算密码哈希所需的时间。这种“缓慢”是阻止野蛮攻击的唯一方法。
如果有办法加快这个过程,攻击者肯定会利用它。所以,不,这里没有捷径。
https://stackoverflow.com/questions/27044315
复制相似问题