From 04ab8838e4915ffd95b6e11eae3ebdc14be93119 Mon Sep 17 00:00:00 2001 From: euromark Date: Fri, 14 Nov 2014 18:58:50 +0100 Subject: [PATCH] Allow options per hasher class for Fallback. --- src/Auth/FallbackPasswordHasher.php | 7 ++++++- .../Auth/FallbackPasswordHasherTest.php | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/Auth/FallbackPasswordHasher.php b/src/Auth/FallbackPasswordHasher.php index 9090296506a..fe658ecc658 100644 --- a/src/Auth/FallbackPasswordHasher.php +++ b/src/Auth/FallbackPasswordHasher.php @@ -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); } } diff --git a/tests/TestCase/Auth/FallbackPasswordHasherTest.php b/tests/TestCase/Auth/FallbackPasswordHasherTest.php index 7decc33fe9b..474848b090d 100644 --- a/tests/TestCase/Auth/FallbackPasswordHasherTest.php +++ b/tests/TestCase/Auth/FallbackPasswordHasherTest.php @@ -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 *