diff --git a/logintoboggan.module b/logintoboggan.module
index 43e6176..63bab00 100755
--- a/logintoboggan.module
+++ b/logintoboggan.module
@@ -414,8 +414,15 @@ function logintoboggan_user_register_submit($form, &$form_state) {
  */
 function logintoboggan_user_login_validate($form, &$form_state) {
   if (isset($form_state['values']['name']) && $form_state['values']['name']) {
-    if ($name = db_result(db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER('%s')", $form_state['values']['name']))) {
-      form_set_value($form['name'], $name, $form_state);
+    if (variable_get('logintoboggan_pressflow_mode', FALSE)) {
+      if ($name = db_result(db_query("SELECT name FROM {users} WHERE mail = '%s'", $form_state['values']['name']))) {
+        form_set_value($form['name'], $name, $form_state);
+      }
+    }
+    else {
+      if ($name = db_result(db_query("SELECT name FROM {users} WHERE LOWER(mail) = LOWER('%s')", $form_state['values']['name']))) {
+        form_set_value($form['name'], $name, $form_state);
+      }
     }
   }
 }
@@ -788,6 +795,12 @@ function logintoboggan_main_settings(&$form_state) {
   }
   $options = array($disabled => $_disabled, 'toboggan/denied' => $_enabled);
 
+  $form['other']['logintoboggan_pressflow_mode'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Enable Pressflow mode'),
+    '#default_value' => variable_get('logintoboggan_pressflow_mode', FALSE),
+    '#description' => t('Pressflow has the LOWER() SQL function removed from user email checks in core, as does Drupal 7. This is a performance enhancement, but could cause discrepancies and multiple accounts for the same email address if you are using PostGreSQL as your data store. Only enable this option if you are sure you are using Pressflow 6 core.'),
+  );
   $form['other']['site_403'] = array(
     '#type' => 'radios',
     '#title' => t('Present login form on access denied (403)'),
@@ -1112,13 +1125,25 @@ function logintoboggan_user($op, &$edit, &$user_edit, $category = NULL) {
     // If login with mail is enabled...
     if (variable_get('logintoboggan_login_with_email', 0)) {
       $uid = isset($user_edit->uid) ? $user_edit->uid : 0;
-      // Check that no user is using this name for their email address.
-      if (isset($edit['name']) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s') AND uid <> %d", $edit['name'], $uid))) {
-        form_set_error('name', t('This name has already been taken by another user.'));
+      if (variable_get('logintoboggan_pressflow_mode', FALSE)) {
+        // Check that no user is using this name for their email address.
+        if (isset($edit['name']) && db_result(db_query("SELECT uid FROM {users} WHERE mail = '%s' AND uid <> %d", $edit['name'], $uid))) {
+          form_set_error('name', t('This name has already been taken by another user.'));
+        }
+        // Check that no user is using this email address for their name.
+        if (isset($edit['mail']) && db_result(db_query("SELECT uid FROM {users} WHERE name = '%s' AND uid <> %d", $edit['mail'], $uid))) {
+          form_set_error('mail', t('This e-mail has already been taken by another user.'));
+        }
       }
-      // Check that no user is using this email address for their name.
-      if (isset($edit['mail']) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER('%s') AND uid <> %d", $edit['mail'], $uid))) {
-        form_set_error('mail', t('This e-mail has already been taken by another user.'));
+      else {
+        // Check that no user is using this name for their email address.
+        if (isset($edit['name']) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(mail) = LOWER('%s') AND uid <> %d", $edit['name'], $uid))) {
+          form_set_error('name', t('This name has already been taken by another user.'));
+        }
+        // Check that no user is using this email address for their name.
+        if (isset($edit['mail']) && db_result(db_query("SELECT uid FROM {users} WHERE LOWER(name) = LOWER('%s') AND uid <> %d", $edit['mail'], $uid))) {
+          form_set_error('mail', t('This e-mail has already been taken by another user.'));
+        }
       }
     }
   }
