You are here

function password_policy_form_alter in Password Policy 6

Same name and namespace in other branches
  1. 7.2 password_policy.module \password_policy_form_alter()
  2. 7 password_policy.module \password_policy_form_alter()

Implements hook_form_alter().

1 call to password_policy_form_alter()
password_policy_password_tab in contrib/password_tab/password_policy_password_tab.pages.inc
Password change form.

File

./password_policy.module, line 476
The password policy module allows you to enforce a specific level of password complexity for the user passwords on the system.

Code

function password_policy_form_alter(&$form, $form_state, $form_id) {
  switch ($form_id) {
    case "user_profile_form":
    case "user_register":

      // Password change form.
      $uid = isset($form['#uid']) ? $form['#uid'] : NULL;

      //if ($uid == 1 && !variable_get('password_policy_admin', 0)) { break; }
      $roles = isset($form['_account']['#value']) ? array_keys($form['_account']['#value']->roles) : array();
      $policy = _password_policy_load_active_policy($roles);
      $translate = array();
      if (!empty($policy['policy'])) {

        // Some policy constraints are active.
        password_policy_add_policy_js($policy, $uid);
        foreach ($policy['policy'] as $key => $value) {
          $translate['constraint_' . $key] = _password_policy_constraint_error($key, $value);
        }
      }

      // Printing out the restrictions.
      if (variable_get('password_policy_show_restrictions', 0) && !empty($translate)) {
        $restriction_html = '<div id="account-pass-restrictions">' . theme('item_list', $translate, t('Password Requirements')) . '</div>';
        if (isset($form['account']) && is_array($form['account'])) {
          $form['account']['pass']['#prefix'] = $restriction_html;
        }
        else {
          $form['pass']['#prefix'] = $restriction_html;
        }
      }

      // Set a custom form validate and submit handlers.
      $form['#validate'][] = 'password_policy_password_validate';
      break;
    case 'password_policy_password_tab':
      $form['submit']['#weight'] = 10;
      break;
  }
}