--- cryptpw.module-orig	2008-10-12 01:31:58.000000000 -0700
+++ cryptpw.module	2010-02-17 13:14:34.000000000 -0800
@@ -14,16 +14,46 @@
       if (variable_get('cryptpw_auto_create',0)) {
         _cryptpw_maildirmake("$homedir/$maildir");
       }
-      if (
-        !db_query(
-          "INSERT INTO {cryptpw} (uid,cryptpw) VALUES (%d,'%s')",
-          $uid,'{MD5}'.base64_encode(pack('H*',$account->pass))
-        )
-      ) {
-        db_query(
-          "UPDATE {cryptpw} SET cryptpw='%s' WHERE uid=%d",
-          '{MD5}'.base64_encode(pack('H*',$account->pass)),$uid
-        );
+      if (variable_get('cryptpw_cryptpw',1)) {
+        if (variable_get('cryptpw_clearpw',0)) {
+          if (
+            !db_query(
+              "INSERT INTO {cryptpw} (uid,cryptpw,clearpw) VALUES (%d,'%s','%s')",
+              $uid,'{MD5}'.base64_encode(pack('H*',$account->pass)),$edit['pass']
+            )
+          ) {
+            db_query(
+              "UPDATE {cryptpw} SET cryptpw='%s',clearpw='%s' WHERE uid=%d",
+              '{MD5}'.base64_encode(pack('H*',$account->pass)),$edit['pass'],$uid
+            );
+          }
+        }
+        else {
+          if (
+            !db_query(
+              "INSERT INTO {cryptpw} (uid,cryptpw) VALUES (%d,'%s')",
+              $uid,'{MD5}'.base64_encode(pack('H*',$account->pass))
+            )
+          ) {
+            db_query(
+              "UPDATE {cryptpw} SET cryptpw='%s' WHERE uid=%d",
+              '{MD5}'.base64_encode(pack('H*',$account->pass)),$uid
+            );
+          }
+        }
+      }
+      else {
+        if (
+          !db_query(
+            "INSERT INTO {cryptpw} (uid,clearpw) VALUES (%d,'%s')",
+            $uid,$edit['pass']
+          )
+        ) {
+          db_query(
+            "UPDATE {cryptpw} SET clearpw='%s' WHERE uid=%d",
+            $edit['pass'],$uid
+          );
+        }
       }
     }
     else {
@@ -128,6 +158,20 @@
       'is not in the above list.'
     ),
   );
+  $form['cryptpw_passwords'] = array(
+    '#type' => 'fieldset',
+    '#title' => t('Password Configuration'),
+    'cryptpw_cryptpw' => array(
+      '#type' => 'checkbox',
+      '#title' => t("Store encrypted passwords in the database"),
+      '#default_value' => variable_get('cryptpw_cryptpw',1),
+    ),
+    'cryptpw_clearpw' => array(
+      '#type' => 'checkbox',
+      '#title' => t("Store unencrypted, clear text passwords in the database"),
+      '#default_value' => variable_get('cryptpw_clearpw',0),
+    ),
+  );
   switch($GLOBALS['db_type']) {
   case 'mysql':
   case 'mysqli':
@@ -223,7 +267,7 @@
           str_pad($tab."SELECT",78),
           str_pad($tab.$tab."u.mail username,",78),
           str_pad($tab.$tab."u.cryptpw,",78),
-          str_pad($tab.$tab."'' clearpw,",78),
+          str_pad($tab.$tab."u.clearpw,",78),
           str_pad($tab.$tab."$uid uid,",78),
           str_pad($tab.$tab."$gid gid,",78),
           str_pad($tab.$tab."CONCAT('$mailspool',u.uid) home,",78),
@@ -278,6 +322,12 @@
     );
     return;
   }
+  if (!$form['cryptpw_passwords']['cryptpw_cryptpw']['#value'] && !$form['cryptpw_passwords']['cryptpw_clearpw']['#value']) {
+    form_set_error('cryptpw_passwords',
+      t('You must specify at least one of the password storage options in '.
+        'the Password Configuration section.')
+    );
+  }
   $create = $form_state['values']['cryptpw_auto_create'];
   $delete = $form_state['values']['cryptpw_auto_delete'];
   if ($create || $delete) {
