最佳实践:在表中存储密码的最安全方法?

发布于 2024-08-08 20:54:52 字数 96 浏览 8 评论 0 原文

我正在使用 PHP。我曾经使用本机mysql函数password()来存储密码。有人告诉我,password() 不再安全了。在 PHP 中存储密码的最佳方法是什么?是MD5吗?

I am using PHP. I used to use native mysql function password() to store passwords. I was told that password() is not safe anymore. What would be the best method to store passwords in PHP? is it MD5?

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

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

发布评论

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

评论(6

顾忌 2024-08-15 20:54:52

2016 年更新答案:

PHC(密码哈希竞赛)的获胜者是 Argon2。截至 2016 年,使用 Argon2 对密码进行哈希处理是最佳实践。

PHC 于 2013 年至 2015 年作为公开竞赛进行——与 NIST 的 AES 和 SHA-3 竞赛流程相同,也是开发加密标准的最有效方法。我们收到了 24 个候选方案,其中包括许多优秀的设计,最终选出了一个获胜者,Argon2,这是一种由卢森堡大学的 Alex Biryukov、Daniel Dinu 和 Dmitry Khovratovich 设计的算法。

我们建议您使用 Argon2 而不是旧算法。

参考实现可在 GitHub 上找到

2012 年更新答案:

我在下面给出的原始答案曾经被认为是最佳实践。然而,哈希计算技术的进步使得这些方案变得脆弱。展望未来,唯一安全的密码哈希方案是迭代哈希,例如 bcryptPBKDF2。有关完整讨论,请参阅Jeff Atwood 的分析

2009 年原始答案:

我建议首先在密码前添加 salt 值,然后是使用相当强大的哈希函数(例如 SHA256。这可以防止明显的(纯文本密码)和不那么明显的(使用 Rainbow 表的攻击 )。

请记住,如果您以这种方式存储密码,您将无法找回用户丢失的密码。他们只能重置密码。这是因为您将使用单向哈希。但为了更安全的密码存储系统,这种限制通常值得权衡。即使您的数据库遭到破坏,攻击者想要恢复您的用户密码仍然非常困难,而且可能不切实际。

Updated Answer 2016:

The winner of the PHC (Password Hashing Competion) was Argon2. Hashing passwords with Argon2 is the best practice as of 2016.

PHC ran from 2013 to 2015 as an open competition—the same kind of process as NIST's AES and SHA-3 competitions, and the most effective way to develop a crypto standard. We received 24 candidates, including many excellent designs, and selected one winner, Argon2, an algorithm designed by Alex Biryukov, Daniel Dinu, and Dmitry Khovratovich from University of Luxembourg.

We recommend that use you use Argon2 rather than legacy algorithms.

The reference implementation is available on GitHub.

Updated Answer 2012:

The original answer I gave below was once considered to be a best practice. However, advances in hash-computing technology have rendered these schemes vulnerable. Going forward, the only secure password hashing schemes are iterative hashes such as bcrypt and PBKDF2. For a full discussion, see Jeff Atwood's analysis.

Original Answer 2009:

I recommend first prepending a salt value to your password, followed by hashing the resultant string with a reasonably strong hashing function like SHA256. This secures against the obvious (plain text passwords) and the not so obvious (attack using Rainbow tables).

Keep in mind that if you store passwords in this way, you will not be able to retrieve a user's lost password. They'll only be able to reset passwords. This is because you'll be using a one way hash. But this limitation is generally worth the tradeoff for a more secure password storage system. Even if your database is compromised, your user's passwords will still be exceedingly difficult and probably unpractical to recover by a would be attacker.

戏剧牡丹亭 2024-08-15 20:54:52

您需要对密码加盐。

vBulletin 在存储密码方面做得非常好。 md5(md5(密码) + 盐);

You need to salt the password.

vBulletin does a pretty good job at storing passwords. md5(md5(password) + salt);

榕城若虚 2024-08-15 20:54:52

为了与另一个答案争论,VBulletin 在散列密码方面做了一项可怕的工作。它们的盐只有 3 个字符长,只能部分提高应用程序的安全性。

请查看 http://www.openwall.com/phpass/ 。他们在使用每个密码唯一的长哈希以及通过 md5 运行密码数千次方面做得非常出色。它是目前最好的 php 哈希系统之一。

To argue with the the other answer, VBulletin does a horrid job of hashing passwords. Their salt is only 3 characters long, only fractionally increasing the security of your application.

Check out http://www.openwall.com/phpass/ . They do an excellent job of using a long hash, unique to each password, and running the password through md5 thousands of times. It is one of the best hashing systems for php out there.

淤浪 2024-08-15 20:54:52

在我看来,如果您可以避免存储用户密码,那么这是您的最佳选择。使用 OpenId(如 Stackoverflow)对用户进行身份验证。或实时身份验证 (http://dev.live.com/liveid/)。如果您确实非常需要自己对用户进行身份验证;按照亚萨在回答中所说的去做。 :)

If you can avoid storing the user password that's your best option, imo. Use OpenId (like Stackoverflow) to authenticate the user. Or Live Authentication (http://dev.live.com/liveid/). If you really, really need to authenticate the users yourself; do what Asaph says in his answer. :)

德意的啸 2024-08-15 20:54:52

盐和哈希。

我们通常使用随机 guid 作为盐,然后使用 SHA512 进行哈希处理。

Salt and hash.

We typically use a random guid as the salt and then SHA512 to hash.

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