【问题标题】:Password storing in 20172017年密码存储
【发布时间】:2017-04-06 10:12:36
【问题描述】:

所以我正在使用我的登录系统在我自己的网站上工作。 我正在研究密码存储部分,并且一直在观看一些 youtube 视频,人们告诉我不要使用 md5 之类的东西,因为它已经过时了。

我观看了 Tom Scott 制作的关于如何不存储密码的视频,他告诉我们查看有关如何正确存储密码的最新教程。

对于我的项目,我确实需要自己存储密码,而不是使用 Facebook 或 Google 之类的任何东西进行登录。

我在 Stack Overflow 上查看了很多网站和问题,但似乎无法从今年找到任何可以解释的内容。

所以现在我想知道 2017 年存储密码的最佳方式是什么? 我需要使用盐和胡椒吗?也许还有别的?目前哪种哈希算法最好?如果可能的话,我想在 php 中使用它。

谁能帮我解答这些问题?

谢谢你:)

【问题讨论】:

标签: algorithm hash salt storing-information pepper


【解决方案1】:

我假设您只想存储用于用户身份验证的密码,并且您明确要求 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 关于安全存储密码的信息。

【讨论】:

    猜你喜欢
    • 2016-09-24
    • 2017-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-18
    • 2010-09-08
    • 2012-05-31
    • 1970-01-01
    相关资源
    最近更新 更多