Browse Source

Help mitigate timing-based user enumeration attacks.

mscherer 8 years ago
parent
commit
8993849d1d
1 changed files with 5 additions and 2 deletions
  1. 5 2
      src/Model/Behavior/PasswordableBehavior.php

+ 5 - 2
src/Model/Behavior/PasswordableBehavior.php

@@ -322,11 +322,11 @@ class PasswordableBehavior extends Behavior {
 		$formField = $this->_config['formField'];
 		$field = $this->_config['field'];
 
+		$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher'], $options);
 		if ($entity->get($formField) !== null) {
 			$cost = !empty($this->_config['hashCost']) ? $this->_config['hashCost'] : 10;
 			$options = ['cost' => $cost];
-			/** @var \Cake\Auth\AbstractPasswordHasher $PasswordHasher */
-			$PasswordHasher = $this->_getPasswordHasher($this->_config['passwordHasher'], $options);
+
 			$entity->set($field, $PasswordHasher->hash($entity->get($formField)));
 
 			if (!$entity->get($field)) {
@@ -346,6 +346,9 @@ class PasswordableBehavior extends Behavior {
 				$entity->unsetProperty($formFieldCurrent);
 				//unset($Model->data[$table->alias()][$formFieldCurrent]);
 			}
+		} else {
+			// To help mitigate timing-based user enumeration attacks.
+			$PasswordHasher->hash('');
 		}
 	}