You are here

function password_policy_constraint_delay_validate in Password Policy 6

Same name and namespace in other branches
  1. 7 constraints/constraint_delay.inc \password_policy_constraint_delay_validate()

Password validation.

File

constraints/constraint_delay.inc, line 33
Password policy constraint callback to set a minimum delay between password changes.

Code

function password_policy_constraint_delay_validate($password, $constraint, $uid) {
  $account = user_load($uid);

  // bypass delay constraint, if account is marked "Force password change on
  // next login."
  if ($account->force_password_change) {
    return TRUE;
  }
  $last_change = db_result(db_query_range("SELECT MAX(created) FROM {password_policy_history} WHERE uid = %d", $uid, 0, 1));
  if (!empty($last_change)) {

    // Constraint is set in hours, so it gets converted to seconds with *60*60.
    return time() - $constraint * 60 * 60 > $last_change;
  }
  return TRUE;
}