### Eclipse Workspace Patch 1.0
#P chiq2008
Index: sites/default/modules/password_policy/password_policy.module
===================================================================
--- sites/default/modules/password_policy/password_policy.module	(revision 302)
+++ sites/default/modules/password_policy/password_policy.module	(working copy)
@@ -31,7 +31,7 @@
 function password_policy_init() {
   global $_password_policy;
 
-  // Save all available constrains in a global variable. 
+  // Save all available constrains in a global variable.
   $dir = drupal_get_path('module', 'password_policy') .'/constraints';
   $constraints = file_scan_directory($dir, '^constraint.*\.inc$');
   foreach ($constraints as $file) {
@@ -159,7 +159,7 @@
     if (isset($policies[$pid])) {
       return $policies[$pid];
     }
-    else { 
+    else {
       $policy = _password_policy_load_policy_by_pid($pid);
       if ($policy) {
         $policies[$pid] = $policy;
@@ -208,7 +208,7 @@
 function password_policy_user($op, &$edit, &$account, $category = NULL) {
   switch ($op) {
     case "validate":
-      if ($category == 'account' && !empty($edit['pass'])) { 
+      if ($category == 'account' && !empty($edit['pass'])) {
         $error = _password_policy_constraint_validate($edit['pass'], $account);
         if ($error) {
           form_set_error('pass', t('Your password has not met the following %requirements:', array('%requirements' => format_plural(count($error), t('requirement'), t('requirements')))) .'<ul><li>'. implode('</li><li>', $error) .'</li></ul>');
@@ -311,50 +311,57 @@
   switch ($form_id) {
     case "user_profile_form":
     case "user_register":
-      // Password change form. 
+      // Password change form.
       $uid = $form['#uid'];
       //if ($uid == 1 && !variable_get('password_policy_admin', false)) { break; }
       $policy = _password_policy_load_active_policy();
       if (!empty($policy['policy'])) {
-        // Some policy constraints are active. 
-	// Print out the javascript which checks the strength of the password.
-	// It overwrites the defaut core javascript function.
-        drupal_add_js(drupal_get_path('module', 'password_policy') .'/password_policy.js', 'module');
-        $s = "/**\n";
-        $s .= " * Evaluate the strength of a user's password.\n";
-        $s .= " *\n";
-        $s .= " * Returns the estimated strength and the relevant output message.\n";
-        $s .= " */\n";
-        $s .= "Drupal.evaluatePasswordStrength = function(value) {\n";
-        $s .= "  var strength = \"high\", msg = [], translate = Drupal.settings.password_policy;\n";
-        // Print out each constraint's javascript password strength evaluation.
-        foreach ($policy['policy'] as $key => $value) {
-          $s .= _password_policy_constraint_js($key, $value, $uid);
-	  // Constraints' error messages are used in javascript. 
-          $translate['constraint_'. $key] = _password_policy_constraint_error($key, $value);
-        }
-        $s .= "  msg = msg.length > 0 ? translate.needsMoreVariation +\"<ul><li>\"+ msg.join(\"</li><li>\") +\"</li></ul>\" : \"\";\n";
-        $s .= "  return { strength: strength, message: msg };\n";
-        $s .= "};\n";
-        drupal_add_js($s, 'inline');
-
-        drupal_add_js(array(
-          'password_policy' => array_merge(array(
-            'strengthTitle' => t('Password quality:'),
-            'lowStrength' => t('Bad'),
-            'mediumStrength' => t('Medium'),
-            'highStrength' => t('Good'),
-            'needsMoreVariation' => t('The password does not include enough variation to be secure.'),
-            'confirmSuccess' => t('Yes'),
-            'confirmFailure' => t('No'),
-            'confirmTitle' => t('Passwords match:')), $translate)),
-          'setting');
+        password_policy_add_policy_js($policy);
       }
       break;
   }
 }
 
 /**
+ * Add password policy JS
+ */
+function password_policy_add_policy_js($policy) {
+  // Some policy constraints are active.
+  // Print out the javascript which checks the strength of the password.
+  // It overwrites the defaut core javascript function.
+  drupal_add_js(drupal_get_path('module', 'password_policy') .'/password_policy.js', 'module');
+  $s = "/**\n";
+  $s .= " * Evaluate the strength of a user's password.\n";
+  $s .= " *\n";
+  $s .= " * Returns the estimated strength and the relevant output message.\n";
+  $s .= " */\n";
+  $s .= "Drupal.evaluatePasswordStrength = function(value) {\n";
+  $s .= "  var strength = \"high\", msg = [], translate = Drupal.settings.password_policy;\n";
+  // Print out each constraint's javascript password strength evaluation.
+  foreach ($policy['policy'] as $key => $value) {
+    $s .= _password_policy_constraint_js($key, $value, $uid);
+  // Constraints' error messages are used in javascript.
+    $translate['constraint_'. $key] = _password_policy_constraint_error($key, $value);
+  }
+  $s .= "  msg = msg.length > 0 ? translate.needsMoreVariation +\"<ul><li>\"+ msg.join(\"</li><li>\") +\"</li></ul>\" : \"\";\n";
+  $s .= "  return { strength: strength, message: msg };\n";
+  $s .= "};\n";
+  drupal_add_js($s, 'inline');
+
+  drupal_add_js(array(
+    'password_policy' => array_merge(array(
+      'strengthTitle' => t('Password quality:'),
+      'lowStrength' => t('Bad'),
+      'mediumStrength' => t('Medium'),
+      'highStrength' => t('Good'),
+      'needsMoreVariation' => t('The password does not include enough variation to be secure.'),
+      'confirmSuccess' => t('Yes'),
+      'confirmFailure' => t('No'),
+      'confirmTitle' => t('Passwords match:')), $translate)),
+    'setting');
+}
+
+/**
  * Implementation of hook_cron().
  */
 function password_policy_cron() {
@@ -370,7 +377,7 @@
         if ($row->uid == 1 && !variable_get('password_policy_admin', false)) { continue; }
 	// Use account creation timestamp if there is no entry in password history table.
         $accounts[$row->uid] = empty($row->created_p) ? $row->created_u : $row->created_p;
-	// Last time a warning was mailed out (if was). We need it because we send warnings only once a day, not on all cron runs. 
+	// Last time a warning was mailed out (if was). We need it because we send warnings only once a day, not on all cron runs.
         $warns[$row->uid] = $row->warning;
 	// The user was last time unblocked (if was). We don't block this account again for some period of time.
         $unblocks[$row->uid] = $row->unblocked;
@@ -533,10 +540,10 @@
   $account = $params['account'];
   $tokens = array(
    '!username' => $account->name,
-   '!site' => variable_get('site_name', 'Drupal'), 
-   '!uri' => $base_url, 
-   '!uri_brief' => substr($base_url, strlen('http://')), 
-   '!date' => format_date(time(), 'medium', '', NULL, $language->language), 
+   '!site' => variable_get('site_name', 'Drupal'),
+   '!uri' => $base_url,
+   '!uri_brief' => substr($base_url, strlen('http://')),
+   '!date' => format_date(time(), 'medium', '', NULL, $language->language),
    '!login_uri' => url('user', array('absolute' => TRUE)),
    '!edit_uri' => url('user/'. $account->uid .'/edit', array('absolute' => TRUE)),
    '!days_left' => $params['days_left'],
@@ -627,7 +634,7 @@
  * @param $pid
  *   The policy id.
  *
- * @return 
+ * @return
  *   A policy array, or NULL if no policy was found.
  */
 function _password_policy_load_policy_by_pid($pid) {
