【问题标题】:Hash method in LaravelLaravel 中的哈希方法
【发布时间】:2015-01-20 16:18:54
【问题描述】:

我有一个关于 Laravel 4.2 中的 Hash::make 方法的问题。我注意到它总是为相同的值返回不同的字符串。所以我想知道这是否会影响如果我想在表中使用他的电子邮件和哈希密码查找用户。如果不是?为什么我没有使用 where 语句(where 电子邮件和 where 密码)从表中获取具有正确凭据的用户的问题?但是当我只使用它工作的电子邮件查找它时.. 我 100% 确信它只是关于 Password 。你怎么看 ?

【问题讨论】:

    标签: hash laravel-4


    【解决方案1】:

    您故意得到不同的哈希值,该函数为每个哈希密码添加一个随机盐。这对于获得安全的哈希很重要。

    // Hash a new password for storing in the database.
    // The function automatically generates a cryptographically safe salt.
    $hashToStoreInDb = Hash::make($password);
    

    不能直接在SQL语句中进行验证,而是可以通过用户名/邮箱搜索用户,获取存储的password-hash,然后用数据库中的password-hash验证输入的密码。

    // 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 = Hash::check($password, $existingHashFromDb);
    

    【讨论】:

      猜你喜欢
      • 2018-09-28
      • 2021-03-30
      • 1970-01-01
      • 2013-11-27
      • 2018-10-31
      • 1970-01-01
      • 2017-11-30
      • 1970-01-01
      相关资源
      最近更新 更多