user1643162
user1643162

Reputation: 27

Need to change laravel hashing from bcrypt to Whirlpool

I need to make the laravel Hash:: function to use Whirlpool instead of bcrypt. This needs to be compatible with the Auth:: class.

Since I am not very experienced with Laravel I don't really know where to start. I've seen the vendor\ircmaxell\password-compat\lib\password.php file.

Should I create a new definition in start of that and try to replace everything so that it uses the php hash function?

I know this is not optimal, but it is required for compability.

Thanks in advance

Upvotes: 1

Views: 1198

Answers (1)

ARW
ARW

Reputation: 3416

In Laravel 4, the Hash class is a facade that uses the BcryptHasher class by default. This class implements the HasherInterface, which can be seen here:

HasherInterface

In order to use Whirlpool instead of Bcrypt, you would simply write a WhirlpoolHasher class that implements the HasherInterface (use the BcryptHasher class to help you) and then bind it to the Hash alias like so:

App::bind('Hash', function()
{
   return new WhirlpoolHasher;
});

You'd put that somewhere global, like routes.php maybe if you don't have a lot of bindings, or perhaps create a bindings.php file and require that from app/start/global.php.

An alternative to binding directly like that would be to alter the HashServiceProvider class to instantiate a WhirlpoolHasher instead of a BcryptHasher, or create your own service provider and add it to the 'providers' array in app/config/app.php instead of the regular HashServiceProvider.

Upvotes: 3

Related Questions