diff --git a/password_policy.test b/password_policy.test index 538640d..16a9af3 100644 --- a/password_policy.test +++ b/password_policy.test @@ -9,7 +9,11 @@ * Base test case class for Password Policy. */ class PasswordPolicyBaseTestCase extends DrupalWebTestCase { - + /** + * The password policy. + * + * @var PasswordPolicy + */ protected $testPolicy; /** @@ -31,7 +35,7 @@ class PasswordPolicyBaseTestCase extends DrupalWebTestCase { * A fully loaded user object with pass_raw property. */ protected function updateUserPassword($account = NULL) { - if ($account == NULL) { + if ($account === NULL) { $account = $this->account; } @@ -42,6 +46,7 @@ class PasswordPolicyBaseTestCase extends DrupalWebTestCase { // Add the raw password so that we can log in as this user. $account->pass_raw = $edit['pass']; + return $account; } @@ -78,7 +83,7 @@ class PasswordPolicyBaseTestCase extends DrupalWebTestCase { * TRUE if the password passes all policy checks, FALSE otherwise. */ protected function checkPolicy(PasswordPolicy $policy, $password, $account = NULL) { - if ($account == NULL) { + if ($account === NULL) { $account = $this->account; } @@ -100,7 +105,7 @@ class PasswordPolicyBaseTestCase extends DrupalWebTestCase { * TRUE if the account matches the policy, FALSE otherwise. */ protected function matchPolicy(PasswordPolicy $policy, $account = NULL) { - if ($account == NULL) { + if ($account === NULL) { $account = $this->account; } @@ -254,9 +259,9 @@ class PasswordPolicyConstraintsTestCase extends PasswordPolicyBaseTestCase { $this->assertTrue($this->checkPolicy($policy, 'password', $this->account), t('Delay constraint passes with new password after delay window expires.'), t('Constraint')); $policy = $this->createPolicy(array('delay' => array('delay' => '24 hours', 'threshold' => 2))); - $this->assertTrue($this->checkPolicy($policy, 'password', $this->account), t('Delay constraint passes with new password before delay window expires but threshold is not reached.'), t('Constraint')); + $this->assertTrue($this->checkPolicy($policy, 'password', $this->account), 'Delay constraint passes with new password before delay window expires but threshold is not reached.', 'Constraint'); $this->account = $this->updateUserPassword($this->account); - $this->assertFalse($this->checkPolicy($policy, 'password', $this->account), t('Delay constraint fails with new password before delay window expires and threshold is reached.'), t('Constraint')); + $this->assertFalse($this->checkPolicy($policy, 'password', $this->account), 'Delay constraint fails with new password before delay window expires and threshold is reached.', 'Constraint'); } /** diff --git a/plugins/constraint/delay.inc b/plugins/constraint/delay.inc index 3359185..f06e4af 100644 --- a/plugins/constraint/delay.inc +++ b/plugins/constraint/delay.inc @@ -12,7 +12,7 @@ $plugin = array( 'prime value' => 'delay', 'config' => array( 'delay' => NULL, - 'threshold' => NULL, + 'threshold' => 1, ), ); @@ -32,9 +32,9 @@ function password_policy_delay_admin_form($form, &$form_state, $constraint) { ); $sub_form['delay_fieldset']['threshold'] = array( '#type' => 'textfield', - '#title' => t('Maximum number of times password can be changed'), + '#title' => t('Maximum number of times password can be changed per time period'), '#default_value' => $constraint->config['threshold'], - '#description' => t('Password can be changed this many times in a period above (if not defined 1 time).'), + '#description' => t('Password can be changed this amount of times per period above (if not defined 1 time).'), '#element_validate' => array('element_validate_integer_positive'), ); return $sub_form; @@ -68,7 +68,6 @@ function password_policy_delay_constraint($password, $account, $constraint) { return TRUE; } - $period_start = strtotime('-' . $constraint->config['delay']); $password_index = !empty($constraint->config['threshold']) ? $constraint->config['threshold'] - 1 : 0; // If password has been changed less times than allowed by threshold, @@ -79,5 +78,5 @@ function password_policy_delay_constraint($password, $account, $constraint) { // Apply constraint if last number of password changes defined by threshold // happened too recently. - return $account->password_history[$password_index]->created <= $period_start; + return $account->password_history[$password_index]->created <= strtotime('-' . $constraint->config['delay']); }