Index: login_security.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/login_security/login_security.install,v
retrieving revision 1.6.2.1
diff -u -r1.6.2.1 login_security.install
--- login_security.install	26 Feb 2009 20:49:21 -0000	1.6.2.1
+++ login_security.install	12 Mar 2009 11:13:04 -0000
@@ -2,16 +2,22 @@
 // $Id: login_security.install,v 1.6.2.1 2009/02/26 20:49:21 deekayen Exp $
 
 /**
+ * @file
+ * Login Security installation routines
+ *
+ */
+
+/**
  * Implementation of hook_install().
  */
 function login_security_install() {
-  drupal_install_schema('login_security_track');
+  drupal_install_schema('login_security');
 }
 
 /**
  * Implementation of hook_schema().
  */
-function login_security_track_schema() {
+function login_security_schema() {
   $schema['login_security_track'] = array(
   'description' => t('Keeps track of failed login attempts and the associated IP address and user name.'),
     'fields' => array(
@@ -32,21 +38,21 @@
         'length' => 64,
         'not null' => TRUE,
         'default' => '',
-        'description' => t("The book ID is the {book}.nid of the top-level page."),
+        'description' => t("Username used in the login ."),
       ),
       'timestamp' => array(
         'type' => 'int',
         'not null' => TRUE,
         'default' => 0,
-        'description' => t("The book ID is the {book}.nid of the top-level page."),
+        'description' => t("Timestamp of the event."),
       ),
     ),
     'indexes' => array(
-      'id' => array('id'),
       'name' => array('name'),
-      'host' => array('host')
+      'host' => array('host'),
+      'timestamp' => array('timestamp'),
     ),
-    'primary key' => array('timestamp')
+    'primary key' => array('id')
   );
 
   return $schema;
@@ -91,6 +97,38 @@
 }
 
 /**
+ * Database clean up update as for #399390
+ * http://drupal.org/node/399390
+ *
+ * Change current primary key to 'id' and add timestamp index
+ *
+ * @return array
+ */
+function login_security_update_6001() {
+  $ret = array();
+  db_drop_primary_key($ret, 'login_security_track');
+  db_add_primary_key($ret, 'login_security_track', array('id'));
+  db_drop_index($ret, 'login_security_track', 'id');
+  db_add_index($ret, 'login_security_track', 'timestamp', array('timestamp'));
+  db_change_field($ret, 'login_security_track', 'name', 'name', array(
+      'type' => 'varchar',
+      'length' => 64,
+      'not null' => TRUE,
+      'default' => '',
+      'description' => t("Username used in the login submission."),
+    )
+  );
+  db_change_field($ret, 'login_security_track', 'timestamp', 'timestamp', array(
+      'type' => 'int',
+      'not null' => TRUE,
+      'default' => 0,
+      'description' => t("Timestamp of the event."),
+    )
+  );
+  return $ret;
+}
+
+/**
  * Implementation of hook_uninstall().
  */
 function login_security_uninstall() {
@@ -111,5 +149,5 @@
   variable_del('login_security_last_login_timestamp');
   variable_del('login_security_last_access_timestamp');
 
-  drupal_uninstall_schema('login_security_track');
+  drupal_uninstall_schema('login_security');
 }
\ No newline at end of file
Index: login_security.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/login_security/login_security.module,v
retrieving revision 1.12
diff -u -r1.12 login_security.module
--- login_security.module	27 Oct 2008 22:02:32 -0000	1.12
+++ login_security.module	12 Mar 2009 11:08:42 -0000
@@ -270,7 +270,7 @@
   }
 
   // Save entry in security log, Username and IP Address
-  login_security_save_pair($name, check_plain(ip_address()));
+  _login_security_add_event($name, check_plain(ip_address()));
 
   // Populate variables to be used in any module message or login operation
   $variables = _login_security_get_variables_by_name($name);
@@ -326,10 +326,14 @@
  * @param $ip
  *   IP Address of the pair.
  */
-function login_security_save_pair($name, $ip) {
-  // Each fail attempt is kept for future minning of advanced bruteforcing
-  // like multiple IP or X-Forwarded-for usage and automated track data cleanup
-  db_query("INSERT INTO {login_security_track} (name, host, timestamp) VALUES ('%s', '%s', %d)", $name, $ip, time());
+function _login_security_add_event($name, $ip) {
+//Each attempt is kept for future minning of advanced bruteforcing like multiple
+//IP or X-Forwarded-for usage and automated track data cleanup
+  $event = new stdClass();
+  $event->host = $ip;
+  $event->name = $name;
+  $event->timestamp = time();
+  drupal_write_record('login_security_track', $event);
 }
 
 /**
@@ -339,7 +343,11 @@
  *   Optional. Add a deny rule in the access control to this IP Address.
  */
 function login_user_block_ip($variables) {
-  db_query("INSERT INTO {access} (mask, type, status) VALUES ('%s', '%s', %d)", $variables['%ip'], 'host', 0);
+  $block = new stdClass();
+  $block->mask = $variables['%ip'];
+  $block->type = 'host';
+  $block->status = 0;
+  drupal_write_record('access', $block);
   watchdog('login_security', 'Banned IP address %ip because of login security configuration', $variables, WATCHDOG_NOTICE);
   form_set_error('void', t(variable_get('login_security_host_hard_banned', LOGIN_SECURITY_HOST_HARD_BANNED), $variables));
 }

