Index: drupal-6.x-dev/includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.198
diff -u -p -r1.198 bootstrap.inc
--- drupal-6.x-dev/includes/bootstrap.inc	25 Oct 2007 15:38:24 -0000	1.198
+++ drupal-6.x-dev/includes/bootstrap.inc	3 Nov 2007 04:13:04 -0000
@@ -831,7 +831,7 @@ function drupal_is_denied($type, $mask) 
   // these, we return 1 (denied). If no matching records or only ones
   // with status = 1, we get no return from db_result, so we return
   // (bool)NULL = 0 (allowed).
-  return (bool) db_result(db_query_range("SELECT 1 FROM {access} WHERE type = '%s' AND LOWER('%s') LIKE LOWER(mask) AND status = 0", $type, $mask, 0, 1));
+  return (bool) db_result(db_query_range("SELECT 1 FROM {access} WHERE type = '%s' AND '%s' LIKE mask AND status = 0", $type, strtolower($mask), 0, 1));
 }
 
 /**
Index: drupal-6.x-dev/modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.8
diff -u -p -r1.8 user.admin.inc
--- drupal-6.x-dev/modules/user/user.admin.inc	27 Oct 2007 15:28:43 -0000	1.8
+++ drupal-6.x-dev/modules/user/user.admin.inc	3 Nov 2007 04:13:04 -0000
@@ -721,7 +721,7 @@ function user_admin_access_add($mask = N
       form_set_error('mask', t('You must enter a mask.'));
     }
     else {
-      db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $edit['mask'], $edit['type'], $edit['status']);
+      db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", strtolower($edit['mask']), $edit['type'], $edit['status']);
       $aid = db_last_insert_id('access', 'aid');
       drupal_set_message(t('The access rule has been added.'));
       drupal_goto('admin/user/rules');
@@ -743,7 +743,7 @@ function user_admin_access_edit($aid = 0
       form_set_error('mask', t('You must enter a mask.'));
     }
     else {
-      db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", $edit['mask'], $edit['type'], $edit['status'], $aid);
+      db_query("UPDATE {access} SET mask = '%s', type = '%s', status = '%s' WHERE aid = %d", strtolower($edit['mask']), $edit['type'], $edit['status'], $aid);
       drupal_set_message(t('The access rule has been saved.'));
       drupal_goto('admin/user/rules');
     }
@@ -779,7 +779,7 @@ function user_admin_access_form(&$form_s
     '#size' => 30,
     '#maxlength' => 64,
     '#default_value' => $edit['mask'],
-    '#description' => '%: '. t('Matches any number of characters, even zero characters') .'.<br />_: '. t('Matches exactly one character.'),
+    '#description' => '%: '. t('Matches any number of characters, even zero characters.') .'<br />_: '. t('Matches exactly one character.') . '<br />' . t('NOTE: For performance reasons, Drupal stores access rules in lower case.'),
     '#required' => TRUE,
   );
   $form['submit'] = array('#type' => 'submit', '#value' => $submit);
Index: drupal-6.x-dev/modules/user/user.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.install,v
retrieving revision 1.2
diff -u -p -r1.2 user.install
--- drupal-6.x-dev/modules/user/user.install	10 Oct 2007 11:39:35 -0000	1.2
+++ drupal-6.x-dev/modules/user/user.install	3 Nov 2007 04:13:04 -0000
@@ -18,7 +18,7 @@ function user_schema() {
         'length' => 255,
         'not null' => TRUE,
         'default' => '',
-        'description' => t('Text mask used for filtering access.'),
+        'description' => t('Text mask used for filtering access. NOTE: For performance reasons, Drupal stores access rules in lower case.'),
       ),
       'type' => array(
         'type' => 'varchar',
@@ -36,6 +36,10 @@ function user_schema() {
       ),
     ),
     'primary key' => array('aid'),
+    'indexes' => array(
+      'mask' => array('mask'),
+      'type' => array('type')
+    ),
   );
 
   $schema['authmap'] = array(
@@ -282,3 +286,13 @@ function user_schema() {
   return $schema;
 }
 
+/**
+ * Add an index to access table and convert all stored masks to lower case.
+ */
+function user_update_6000() {
+  $ret = array();
+  db_add_index($ret, 'access', 'mask', array('mask'));
+  db_add_index($ret, 'access', 'type', array('type'));
+  $ret[] = update_sql('UPDATE {access} SET mask = LOWER(mask)');
+  return $ret;
+}
Index: drupal-6.x-dev/modules/user/user.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.module,v
retrieving revision 1.857
diff -u -p -r1.857 user.module
--- drupal-6.x-dev/modules/user/user.module	27 Oct 2007 14:01:12 -0000	1.857
+++ drupal-6.x-dev/modules/user/user.module	3 Nov 2007 04:13:04 -0000
@@ -2055,7 +2055,7 @@ function user_block_user_action(&$object
  */
 function user_block_ip_action() {
   $ip = ip_address();
-  db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $ip, 'host', 0);
+  db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", strtolower($ip), 'host', 0);
   watchdog('action', 'Banned IP address %ip', array('%ip' => $ip));
 }
 
