How to extend Laravel's bcrypt method
I have made a php class that combines different hash algorithms, and I would like to implement it within the bcrypt()
laravel's method.
My current solution is to access the AuthController and replace bcrypt($data['password'])
by bcrypt(phashp($data['password']))
, but I wonder if there is a way to modify the method without changing the code in the Illuminate Hashing vendor nor in the AuthController.
How can I extend this method?
Thank you!
Answer
What you need to do, is go into config/app.php
and replace Illuminate\Hashing\HashServiceProvider::class,
with custom one and you can now set your custom singleton. In above provider there is:
$this->app->singleton('hash', function () {
return new BcryptHasher;
});
and you can do:
$this->app->singleton('hash', function () {
return new MyCustomHasher;
});
and of course define MyCustomHasher
class that will implement HasherContract
interface
It should work without a problem, because when you look at bcrypt
definition:
function bcrypt($value, $options = [])
{
return app('hash')->make($value, $options);
}
you see that you run finnally run class that is bound to hash
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?