所以我正在使用我的登录系统在我自己的网站上工作。 我正在研究密码存储部分,并且一直在看一些 youtube 视频,人们告诉我不要使用像 md5 这样的东西,因为它已经过时了。
我看过 Tom Scott 制作的关于如何不存储密码的视频,他告诉我们查看最近的教程,了解如何正确地做到这一点。
对于我的项目,我确实需要自己存储密码,而不是使用 Facebook 或 Google 之类的任何东西进行登录。
我在 Stack Overflow 上查看了很多网站和问题,但似乎找不到今年的任何解释。
所以现在我想知道 2017 年存储密码的最佳方式是什么? 我需要用盐和胡椒吗?也许别的什么?哪种哈希算法目前最好?如果可能的话,我想在 php 中使用它。
谁能帮我解决这些问题?
谢谢你:)
最佳答案
我假设您只想存储用于用户身份验证的密码,并且您明确要求 PHP 解决方案,因此答案必须是使用 PHP 函数 password_hash()。此函数是最新的,可以处理密码散列的所有棘手部分。
// Hash a new password for storing in the database.
// The function automatically generates a cryptographically safe salt.
$hashToStoreInDb = password_hash($password, PASSWORD_DEFAULT);
// Check if the hash of the entered login password, matches the stored hash.
// The salt and the cost factor will be extracted from $existingHashFromDb.
$isPasswordCorrect = password_verify($password, $existingHashFromDb);
如果你对更深入的信息感兴趣,你可以看看我的tutorial关于安全存储密码。
关于algorithm - 密码存储于2017年,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43252165/