我应该如何将盐合并到我的密码哈希中?

发布于 2024-08-17 07:12:06 字数 199 浏览 2 评论 0原文

强多少

return sha1($salt.sha1($passwd));

与以下相比

return sha1($salt.$passwd);

$salt 是长度为 12 的每个用户字符串,由强随机 ASCII 组成。

How much stronger would

return sha1($salt.sha1($passwd));

be compared to just:

return sha1($salt.$passwd);

$salt is a per-user string of length 12 consisting of strong random ASCII.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

花开雨落又逢春i 2024-08-24 07:12:06

它的强度恰好是原来的两倍,因为攻击者需要执行两倍的 SHA1 计算才能进行暴力攻击。

当然,这仍然不够令人印象深刻。另一方面,循环执行 SHA1 5000 次对于授权来说是实用的,但会使攻击时间延长 5000 倍 - 这种技术称为 重点加强。然而,它实际上只是 Jacco 提到的适应性成本哈希算法的穷人的替代品。

It's exactly twice as strong, because the attacker needs to perform twice as many SHA1 calculations for a brute force attack.

Of course, that is still not exactly impressive. On the other hand, doing the SHA1 5000 times in a loop is practical for authorization, but makes attacks take 5000 times longer - this technique is known as key strengthening. It is, however, really just a poor man's substitute for the adaptible-cost hash algorithms that Jacco mentions.

风轻花落早 2024-08-24 07:12:06

乍一看,如果没有丰富的加密知识,我会说它一点也不强。

顺便说一句,通常建议使用

sha1($login.$salt.$passwd);

相同的密码,这样 2 个用户就不会拥有相同的哈希值。

At first glance, and without strong knowledge in crypto, I'd say it's not stronger at all.

By the way, it's usually advised to use

sha1($login.$salt.$passwd);

so that 2 users with the same password won't have the same hash.

A君 2024-08-24 07:12:06

据我所知,实力上没有区别。

由于通常的做法是将盐添加到密码哈希值之前,因此攻击者通常知道盐。但这并不能破坏盐的目的。

一般来说,将 $login/$username 添加到哈希中并不是一个好主意 (Vinzz< /a> 的解决方案),因为如果用户更改他或她的用户名,将会导致问题。更好的解决方案是使用随机盐

使用的哈希算法确实会产生影响。 SHA1 被视为加密已损坏并且不应该用于散列密码。

一般来说,BCRYPT(一种基于 Blowfish 的自适应成本哈希算法)被认为是最佳实践(PHP 的 CRYPT_BLOWFISH 标志)。 php.net/crypt" rel="nofollow noreferrer">crypt();)
其他可靠的选项是 SHA256 及更高版本。

编辑:
我在这里写了一个关于加盐的较长答案:stackoverflow.com/问题/1645161/salt- Generation-and-open-source-software/

As far as I know there is no difference in strength.

Since it is common practice to prepend the salt to the password hash, the salt is generally known to an attacker. But this does not defeat the purpose of the salt.

It is generally speaking not a a good idead to add the $login/$username to the hash (Vinzz's solution) as it will cause problems if the user changes his or her username. A better solution is to use a random salt.

The used hashing algorithm does make a difference. SHA1 is considered cryptographically broken and should not be used to hash passwords.

Gennerally speaking BCRYPT (a Blowfish based adaptable-cost hashing algorithm) is considdered best to be the practice (CRYPT_BLOWFISH flag for PHP's crypt();)
Other solid options are SHA256 and above.

Edit:
I wrote a longer answer on salting here: stackoverflow.com/questions/1645161/salt-generation-and-open-source-software/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文