Laravel 5:使用SHA1而不是Bcrypt

The*_*ish 6 php sha1 extending laravel laravel-5

我正在尝试扩展HashServiceProviderlaravel 5中的默认Bcrypt ,以改为使用SHA1加密.

使用这个问题的答案:如何在Laravel 4中使用SHA1加密而不是BCrypt?http://laravel.com/docs/5.0/extending#container-based-extension上的官方文档,我设法编写以下代码:

app/Providers/ShaHashServiceProvider.php中


    use App\ShaHasher;
    use Illuminate\Hashing\HashServiceProvider;

    class ShaHashServiceProvider extends HashServiceProvider {

        public function boot()
        {
            parent::boot();

            $this->app->bindShared('hash', function()
            {
                return new ShaHasher();
            });
        }

    }

app/ShaHasher.php中


    use Illuminate\Contracts\Hashing\Hasher as HasherContract;

    class ShaHasher implements HasherContract {

        public function make($value, array $options = array()) {
            $value = env('SALT', '').$value;
            return sha1($value);
        }

        public function check($value, $hashedValue, array $options = array()) {
            return $this->make($value) === $hashedValue;
        }

        public function needsRehash($hashedValue, array $options = array()) {
            return false;
        }

    }

app/config/app.php中


    'providers' => [
            ...
            //'Illuminate\Hashing\HashServiceProvider',
            'App\Providers\ShaHashServiceProvider',
            ...
    ],

我也使用开箱即用的Laravels AuthController来处理登录.

但它似乎不像我想的那样有效.我第一次尝试登录时,一切都运行得很好.然后我退出了,从那时起,每次登录尝试都失败了.

我没有收到任何错误,只是" 哎呀!您的输入存在一些问题.这些凭据与我们的记录不符. "消息.

我想知道到底出了什么问题,在哪里?我希望你们中的一些天才可以帮助我!

The*_*ish 7

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

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


    use App\ShaHasher;
    use Illuminate\Hashing\HashServiceProvider;

    class ShaHashServiceProvider extends HashServiceProvider {

        public function register()
        {
            $this->app->singleton('hash', function() { return new ShaHasher; });
        }

    }