You are here

function _password_policy_load_policy_from_db in Password Policy 7

Loads the policy that meets the specified conditions from the database.

Parameters

array $conditions: Associative array of conditions where keys are field names and values are field values.

Return value

array|false A policy array or FALSE if no policy was found.

2 calls to _password_policy_load_policy_from_db()
password_policy_load_policy_by_name in ./password_policy.module
Loads the policy with the specified name.
_password_policy_load_policy_by_pid in ./password_policy.module
Loads the policy with the specified id.

File

./password_policy.module, line 1467
Allows enforcing restrictions on user passwords by defining policies.

Code

function _password_policy_load_policy_from_db(array $conditions) {
  $query = db_select('password_policy', 'p', array(
    'target' => 'slave',
  ))
    ->fields('p');
  foreach ($conditions as $field => $value) {
    $query
      ->condition($field, $value);
  }
  $row = $query
    ->execute()
    ->fetchAssoc();
  if ($row) {
    $row['constraints'] = unserialize($row['constraints']);

    // Fetch roles.
    $row['roles'] = array();
    $result = db_select('password_policy_role', 'p', array(
      'target' => 'slave',
    ))
      ->fields('p', array(
      'rid',
    ))
      ->condition('pid', $row['pid'])
      ->execute();
    foreach ($result as $role) {
      $row['roles'][$role->rid] = $role->rid;
    }

    // Fetch authentication modules.
    _password_policy_load_policy_excluded_authentication_modules($row);
    return $row;
  }
  return FALSE;
}