How can I change the password crypting algorithm for the auth in Laravel. I see that in the register controller there is this function:
protected function create(array $data)
{
return User::create([
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
and I can change the bcrypt function here but how to make the login check the password with my custom hashing algorithm that I will make?
You need to create your own
HashServiceProvider
(its a service provider) so use artisan to create your own (you may call it same as original)Now copy most of the body of stock HashServiceProvider (the stock one can be found in \Illuminate\Hashing\HashServiceProvider.php) and fix namespaces and imports. Now go to config/app.php and find HashServiceProvider and change stock HashServiceProvider for your own service provider, given that you did exactly as I guided you should notice no change what so ever.
Now you have to create (implement) your own hashing functions. You have two options:
A. extend the original BcryptHasher
example of this method can be found in Kyslik/django-bcrypt repository
B. create new class and implement Hasher interface
Finally in your service provider (HashServiceProvider) change
register()
method to return your implementation of hashing.Do a
$ composer dump-autoload
and you may enjoy your own shiny hashing.