Browse Source

Allow options per hasher class for Fallback.

euromark 11 years ago
parent
commit
04ab8838e4

+ 6 - 1
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);
 		}
 	}

+ 18 - 0
tests/TestCase/Auth/FallbackPasswordHasherTest.php

@@ -58,6 +58,24 @@ class FallbackPasswordHasherTest extends TestCase {
 	}
 
 /**
+ * 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
  *
  * @return void