I want to implement another hasher in Laravel 4 (here Whirlpool, but my problem isn't Hash related) following this post.
The difference in my project is that I've created my services in folders and namespaces:
Laravel
|-- app
| |-- config
| | +-- app.php
| |
| |-- controllers
| | +-- UserController.php
|
|-- lib
| +-- Max13
| +-- Services
| +-- Hash
| |-- WhirlpoolHasher.php
| +-- WhirlpooHashServiceProvider.php
|
|-- start
| +-- global.php
|
+-- composer.json
Here are the relevant extracts of each files:
composer.json:
[...]
"autoload": {
"classmap": [
[...]
"app/lib",
]
}
[...]
app/config/app.php:
<?php
return array(
[...]
'providers' => array(
[...]
'Illuminate\Workbench\WorkbenchServiceProvider',
'Max13\Services\Hash\WhirlpoolHashServiceProvider',
),
[...]
);
app/controllers/UserControllers.php:
<?php
class UserController extends BaseController
{
/**
* Treat GET methods.
*
* @return Response
*/
public function getUser()
{
if (Input::has('username', 'password')) {
$username = Input::get('username');
$password = Hash::make(Input::get('password'));
Response::json($password);
} else {
return 'unknown';
}
}
}
lib/Max13/Services/Hash/WhirlpoolHasher.php:
<?php namespace Max13\Services\Hash;
class WhirlpoolHasher implements \Illuminate\Hashing\HasherInterface
{
public function make($value, array $options = array())
{
$hash = hash('whirlpool', $value);
if ($hash === null) {
throw new \RuntimeException("Wirlpool hashing not supported.");
}
return $hash;
}
public function check($value, $hashedValue, array $options = array())
{
return strcasecmp($this->make($value), $hashedValue) === 0;
}
public function needsRehash($hashedValue, array $options = array())
{
return ctype_alnum($hashedValue) && strlen($hashedValue) === 128;
}
}
lib/Max13/Services/Hash/WhirlpoolHashServiceProvider.php:
<?php namespace Max13\Services\Hash;
class WhirlpoolHashServiceProvider extends \Illuminate\Support\ServiceProvider
{
public function register()
{
$this->app['hash'] = $this->app->share(function () {
return new WhirlpoolHasher();
});
}
public function provides()
{
return array('hash');
}
}
I think I've done everything correctly (I didn't forget php composer dump-autoload
), I don't have any errors BUT when I query my website on /user?username=foo&password=bar
I get a Bcrypt
hash (60 chars, Whirlpool
is 128). Does anyone know what I'm missing?
Remove laravel's default 'Illuminate\Hashing\HashServiceProvider',
provider (around line 93) from your config/app.php and you should be good to go.