? genpass_override.patch
Index: genpass.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/genpass/genpass.module,v
retrieving revision 1.2
diff -u -p -r1.2 genpass.module
--- genpass.module	3 Mar 2009 13:23:47 -0000	1.2
+++ genpass.module	26 Nov 2009 02:34:48 -0000
@@ -7,12 +7,14 @@ function _genpass_default_entropy() {
 /**
  * Generate a new password
  * Based on the original D6 user_password function (with more characters)
- *
+ * @override if true, allow other modules to modify the generated password.
  * @return a fresh password according to the settings made in /admin/user/settings
  *
  * @see genpass_form_alter()
  */
-function genpass_password() {
+function genpass_password($override = true) {
+  // First, generate a password
+  
   $pass = '';
   $length = variable_get('genpass_length', 8);
   $allowable_characters = variable_get('genpass_entropy', _genpass_default_entropy());
@@ -27,6 +29,29 @@ function genpass_password() {
     $pass .= $allowable_characters[mt_rand(0, $len)];
   }
 
+  // if we don't want to override, just return pass
+  
+  if(!$override) {
+    return $pass;
+  }
+  
+  // Give other modules a chance to modify the password or come up with a
+  // password of their own. They can do this by implementing the hook
+  // hook_genpass_genpass()
+  
+  $potential_password_array = genpass_extend('genpass', $pass);
+  
+  // take the first valid password from the hook implementations.
+  // if several modules implement the hook, only the first hook actually
+  // works, unless it is an empty string or not a string at all.
+  
+  foreach($potential_password_array as $potential_password) {
+    if(is_string($potential_password) && strlen($potential_password)) {
+      $pass = $potential_password;
+      break;
+    }
+  }
+  
   return $pass;
 }
 
@@ -152,5 +177,34 @@ function genpass_user_admin_register_val
   return $form;
 }
 
+/**
+* code taken from http://civicactions.com/blog/writing_extensible_drupal_modules_part_1
+* invokes a custom hook for this module.
+* @param $hook_name is the name of the hook to call, eg "certs_api_redirect"
+* @param $op is the action that a module should run
+* @param $data is signit data
+* @param $config is configuration data
+* @return an array of data 
+* 
+*/
+function genpass_extend($hook_name, $op = null, $data = null, $config = null) {
+  $hook_name = 'genpass_' . $hook_name;
+
+  $items = array();
+  
+  foreach (module_implements($hook_name) as $module) {
+    if ($new = module_invoke($module, $hook_name, $op, $data, $config)) {
+      if(is_array($new)) {
+        $items = array_merge($items, $new);
+      } else {
+        $items[] = $new;
+      }
+    }
+  }
+  // make sure we return an array
+  if (! is_array($items)) { return array(); }
+  return $items;
+}
+
 
 
