Skip to content

Commit

Permalink
Allow options per hasher class for Fallback.
Browse files Browse the repository at this point in the history
  • Loading branch information
euromark committed Nov 14, 2014
1 parent 1b786b0 commit 04ab883
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Auth/FallbackPasswordHasher.php
Expand Up @@ -49,7 +49,12 @@ class FallbackPasswordHasher extends AbstractPasswordHasher {
*/
public function __construct(array $config = array()) {
parent::__construct($config);
foreach ($this->_config['hashers'] as $hasher) {
foreach ($this->_config['hashers'] as $key => $hasher) {
if (!is_int($key)) {
$hasher += [
'className' => $key,
];
}
$this->_hashers[] = PasswordHasherFactory::build($hasher);
}
}
Expand Down
18 changes: 18 additions & 0 deletions tests/TestCase/Auth/FallbackPasswordHasherTest.php
Expand Up @@ -57,6 +57,24 @@ public function testCheck() {
$this->assertTrue($hasher->check('foo', $otherHash));
}

/**
* Tests that the check method will work with configured hashers including configs
* per hasher.
*
* @return void
*/
public function testCheckWithConfigs() {
$hasher = new FallbackPasswordHasher(['hashers' => ['Default', 'Weak' => ['hashType' => 'md5']]]);
$legacy = new WeakPasswordHasher(['hashType' => 'md5']);
$simple = new DefaultPasswordHasher();

$hash = $simple->hash('foo');
$legacyHash = $legacy->hash('foo');
$this->assertTrue($hash !== $legacyHash);
$this->assertTrue($hasher->check('foo', $hash));
$this->assertTrue($hasher->check('foo', $legacyHash));
}

/**
* Tests that the password only needs to be re-built according to the first hasher
*
Expand Down

0 comments on commit 04ab883

Please sign in to comment.