【问题标题】:Laravel 5: Using SHA1 instead of BcryptLaravel 5:使用 SHA1 代替 Bcrypt
【发布时间】:2015-05-13 00:16:48
【问题描述】:

我正在尝试在 laravel 5 中扩展默认的 Bcrypt HashServiceProvider,以改用 SHA1 加密。

使用这个问题的答案:How to use SHA1 encryption instead of BCrypt in Laravel 4?http://laravel.com/docs/5.0/extending#container-based-extension 的官方文档,我设法编写了以下代码:

app/Providers/ShaHashServiceProvider.php

使用 App\ShaHasher; 使用 Illuminate\Hashing\HashServiceProvider; 类 ShaHashServiceProvider 扩展 HashServiceProvider { 公共函数启动() { 父::boot(); $this->app->bindShared('hash', function() { 返回新的 ShaHasher(); }); } }

app/ShaHasher.php

使用 Illuminate\Contracts\Hashing\Hasher 作为 HasherContract; 类 ShaHasher 实现 HasherContract { 公共函数 make($value, 数组 $options = array()) { $value = env('SALT', '').$value; 返回sha1($值); } 公共函数检查($value,$hashedValue,数组 $options = array()) { 返回 $this->make($value) === $hashedValue; } 公共函数需要Rehash($hashedValue, array $options = array()) { 返回假; } }

app/config/app.php

'供应商' => [ ... //'Illuminate\Hashing\HashServiceProvider', 'App\Providers\ShaHashServiceProvider', ... ],

我还在使用开箱即用的 Laravel AuthController 来处理登录。

但它似乎没有按我的预期工作。我第一次尝试登录时,一切正常。然后我退出了,从那以后,每次登录尝试都失败了。

我没有收到任何错误,只是“糟糕!您的输入有一些问题。这些凭据与我们的记录不匹配。”消息。

我想知道到底出了什么问题,哪里出了问题?希望各位高手能帮帮我!

【问题讨论】:

  • 为什么? SHA1 不是很安全。
  • @lukasgeiter - 我正在将一个旧的 CakePHP 应用程序(使用 SHA1)迁移到 Laravel 5。
  • 然后我会尝试将密码实际迁移到 bcrypt。 This answer describes how such migration process could work
  • @lukasgeiter 我也考虑过这种可能性,但我不喜欢更改用户架构并为登录过程添加额外逻辑的想法,因为不需要那样做安全(在这种情况下)。我什至找到了有关如何迁移密码的指南:laravel-tricks.com/tricks/…
  • 无论如何,我仍然很好奇为什么这段代码不起作用:-)

标签: php laravel sha1 laravel-5 extending


【解决方案1】:

我自己解决了这个问题:-)

app/Providers/ShaHashServiceProvider.php 中,我覆盖了错误的方法 boot(),而实际上我应该覆盖的方法 register()

使用 App\ShaHasher; 使用 Illuminate\Hashing\HashServiceProvider; 类 ShaHashServiceProvider 扩展 HashServiceProvider { 公共函数寄存器() { $this->app->singleton('hash', function() { return new ShaHasher; }); } }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-08
    • 1970-01-01
    相关资源
    最近更新 更多