Laravel 5: using SHA1 instead of Bcrypt

I am trying to extend the default HashServiceProvider in laravel 5 to use SHA1 encryption instead.

Using the answer from this question: How to use SHA1 encryption instead of BCrypt in Laravel 4? and the official documentation at http://laravel.com/docs/5.0/extending#container-based-extension , I managed to prepare the following code:

In 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 ();
             });
         }

     }

In the application /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;
         }

     }

In app / config / app.php

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

I also use Laravels from the AuthController box to handle logins.

But it seems that it does not work as I expected. The first time I tried to log in, everything worked perfectly. Then I logged out, and since then any attempt to log in has failed.

I get no errors, just "Oops!" There were some problems with your input. These credentials do not match our records. "Message.

I wonder what exactly happened, and where? I hope some of you geniuses can help me!

+6
source share
1 answer

I myself solved this problem :-)

In app / Providers / ShaHashServiceProvider.php, I overridden the incorrect boot() method when it was actually the register() method that I would have to override.

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

     class ShaHashServiceProvider extends HashServiceProvider {

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

     }

+6
source

Source: https://habr.com/ru/post/983635/


All Articles