1

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

user1643162
  • 27
  • 1
  • 7

1 Answers1

3

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.

ARW
  • 3,306
  • 7
  • 32
  • 41
  • Thank you very much. This worked perfectly. I had to change the HashServiceProvider though. Thanks again. – user1643162 Jun 05 '13 at 14:47
  • Great, no problem! Might be better to create your own HashServiceProvider in hindsight, as you might run into problems with your altered version if you update in Composer. Just something to consider. – ARW Jun 05 '13 at 15:17