The essence of the problem is as follows. There is a base with a users table. The password field contains a password, which can be obtained by running the following request:

'SELECT DECODE('some_user_password','some_secret_key') AS password FROM users WHERE id = 'test'';

The secret for the DECODE() function is known to me (taken from the working project configs, which is written in Perl and not by me).

Data is added to this table with and using the ENCODE('some_user_password','some_secret_key') function ENCODE('some_user_password','some_secret_key') in the sql query itself. As far as I could understand from the perl code, this is the only hash method used by this application.

What can be done to make the standard Laravel authentication method work (changing the base is not an option). How can I change the standard password hashing method in Laravel?

  • To understand how to change the password hashing method in Laravel, you need to understand what method the password hashes perl-function DECODE ... - Ep1demic

1 answer 1

So that you can log in through Laravel to your database - you need to create your own driver for authorization in which to override the method that checks passwords or create your own hasher, I will tell you by the first option.

The stages are not small, so I'll show you right away with an example:

1) First you need to create your own Provider, which is inherited from EloquentUserProvider and override the validateCredentials method in it:

 namespace App\Extensions; use Illuminate\Support\Str; use Illuminate\Auth\EloquentUserProvider; class CustomUserProvider extends EloquentUserProvider { /** * Validate a user against the given credentials. * * @param \Illuminate\Contracts\Auth\Authenticatable $user * @param array $credentials * @return bool */ public function validateCredentials(UserContract $user, array $credentials) { $plain = $credentials['password']; return $this->hasher->check($plain, $user->getAuthPassword()); } } 

This is the original method, change the logic of checking for your own in it, the main thing is that the output will have a bool value. The variable $plain is the password that the user entered on the login form.

2) Now let us say that the framework will work with users through our new provider. To do this, change a couple of lines in config/auth.php :

 'users' => [ 'driver' => 'custom', 'model' => App\Entities\User::class //Обратите внимание на путь к модели, у меня он не стандартный ], 

3) But before you check, you must declare the provider. To do this, we specify the AuthServiceProvider in the boot method in the AuthServiceProvider method:

 \Auth::provider('custom', function ($app, array $config) { return new CustomUserProvider($app['hash'], $config['model']); }); 

4) Now you can check the authorization, it will work through the new provider.

PS There are some problems with formatting the code in the answer, but it seems to work.

  • Thank! Everything worked, it was worth only to see a worthy explanation. I am studying this framework for less than a week) - SWic
  • @SWic less than a week and already such tasks) - Yaroslav Molchan
  • there were such tasks at work. so I decided to study normally, not to do it soon on ready solutions from the network on php - SWic