Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.194
diff -u -p -r1.194 bootstrap.inc
--- includes/bootstrap.inc	5 Oct 2007 14:50:25 -0000	1.194
+++ includes/bootstrap.inc	7 Oct 2007 23:26:46 -0000
@@ -825,7 +825,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: modules/user/user.admin.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.admin.inc,v
retrieving revision 1.5
diff -u -p -r1.5 user.admin.inc
--- modules/user/user.admin.inc	2 Oct 2007 16:03:17 -0000	1.5
+++ modules/user/user.admin.inc	7 Oct 2007 23:26:50 -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');
     }
Index: modules/user/user.install
===================================================================
RCS file: /cvs/drupal/drupal/modules/user/user.install,v
retrieving revision 1.1
diff -u -p -r1.1 user.install
--- modules/user/user.install	5 Oct 2007 16:07:22 -0000	1.1
+++ modules/user/user.install	7 Oct 2007 23:26:50 -0000
@@ -12,6 +12,9 @@ function user_schema() {
       'type'   => array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''),
       'status' => array('type' => 'int', 'not null' => TRUE, 'default' => 0, 'size' => 'tiny')
     ),
+    'indexes' => array(
+      'type'        => array('type'),
+    ),
     'primary key' => array('aid'),
   );
 
@@ -86,3 +89,12 @@ 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', 'type', array('type'));
+  $ret[] = update_sql('UPDATE {access} SET mask = LOWER(mask)');
+  return $ret;
+}
