Add IPB2 authentication module
authorRobert Sesek <rsesek@bluestatic.org>
Sat, 14 Feb 2009 22:05:51 +0000 (17:05 -0500)
committerRobert Sesek <rsesek@bluestatic.org>
Thu, 19 Mar 2009 20:10:29 +0000 (16:10 -0400)
* includes/auth/auth_ipb2.php: New file
* includes/auth/config.php.new: Add config directives

includes/auth/auth_ipb2.php [new file with mode: 0644]
includes/auth/config.php.new

diff --git a/includes/auth/auth_ipb2.php b/includes/auth/auth_ipb2.php
new file mode 100644 (file)
index 0000000..156b08a
--- /dev/null
@@ -0,0 +1,130 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar
+|| # Copyright (c)2004-2009 Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version 2 of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+require_once 'includes/auth/auth.php';
+
+/**
+ * Authentication: IPB2
+ *
+ * Authentication system for Invision Power Board 2
+ *
+ * @author             Blue Static
+ * @copyright  Copyright (c)2004 - 2009, Blue Static
+ * @package            Bugdar
+ *
+ */
+class AuthenticationIPB2 extends Authentication
+{
+       /**
+        * Map Bugdar fields to IPB ones
+        * @var array
+        */
+       var $fieldMap = array(
+               'authid'                => 'id',
+               'displayname'   => 'name',
+               'email'                 => 'email'
+       );
+       
+       /**
+        * IPB2 table prefix
+        * @var string
+        */
+       var $tablePrefix;
+       
+       /**
+        * Cookie prefix
+        * @var string
+        */
+       var $cookiePrefix;
+       
+       // ###################################################################
+       function _setupDatabase()
+       {
+               parent::_setupDatabase();
+               
+               include 'includes/auth/config.php';
+               $this->tablePrefix = $config['auth']['IPB2']['tablePrefix'];
+               $this->cookiePrefix = $config['auth']['IPB2']['cookiePrefix'];
+       }
+       
+       // ###################################################################
+       function _fetchCookieUniqueId()
+       {
+               return $this->registry->input_clean($this->cookiePrefix . 'member_id', TYPE_UINT);
+       }
+       
+       // ###################################################################
+       function _fetchCookiePassword()
+       {
+               return $this->registry->in[$this->cookiePrefix . 'pass_hash'];
+       }
+       
+       // ###################################################################
+       function _fetchUserUsingCookies()
+       {
+               return $this->authDb->query_first("SELECT * FROM {$this->tablePrefix}members WHERE id = " . $this->_fetchCookieUniqueId());
+       }
+       
+       // ###################################################################
+       function _verifyCookieData()
+       {
+               return ($this->_fetchCookiePassword() == $this->authUser['member_login_key']);
+       }
+       
+       // ###################################################################
+       function _fetchUserWithIdentifier($username)
+       {
+               return $this->authDb->query_first("SELECT * FROM {$this->tablePrefix}members WHERE name = '" . $this->authDb->escape_string($username) . "'");
+       }
+       
+       // ###################################################################
+       function _verifyLoginUser($password)
+       {
+               $cvg = $this->authDb->query_first("SELECT * FROM {$this->tablePrefix}members_converge WHERE converge_email = '" . $this->authUser['email'] . "'");
+               return (md5(md5($cvg['converge_pass_salt']) . md5($password)) == $cvg['converge_pass_hash']);
+       }
+       
+       // ###################################################################
+       function clearCookies()
+       {
+               $this->registry->funct->cookie($this->cookiePrefix . 'member_id');
+               $this->registry->funct->cookie($this->cookiePrefix . 'pass_hash');
+               $this->registry->funct->cookie($this->cookiePrefix . 'ipb_stronghold');
+               $this->authDb->query("DELETE FROM {$this->tablePrefix}sessions WHERE id = '" . $this->authDb->escape_string($this->registry->in[$this->cookiePrefix . 'session_id']) . "'");
+               $this->registry->funct->cookie($this->cookiePrefix . 'session_id');
+       }
+       
+       // ###################################################################
+       function _setCookies($sticky = false)
+       {
+               $this->registry->funct->cookie($this->cookiePrefix . 'member_id', $this->authUser['id']);
+               $this->registry->funct->cookie($this->cookiePrefix . 'pass_hash', $this->authUser['member_login_key']);
+               
+               include 'includes/auth/config.php';
+               $ip = explode('.', $_SERVER['REMOTE_ADDR']);
+               $stronghold = md5(md5($this->authUser['id'] . '-' . $ip[0] . '-' . $ip[1] . '-' . $this->authUser['member_login_key']) . md5($config['auth']['dbPassword'] . $config['auth']['dbUser']));
+               $this->registry->funct->cookie($this->cookiePrefix . 'ipb_stronghold', $stronghold);
+               
+               $this->registry->funct->cookie($this->cookiePrefix . 'session_id');
+       }
+}
+
+?>
\ No newline at end of file
index 5371043c7848d50d6b38cb86f42ab888ed22093b..d5bb4af61782c18922e3dedca5e49a746b738d20 100644 (file)
@@ -76,4 +76,17 @@ $config['auth']['vBulletin3']['tablePrefix'] = '';
  */
 $config['auth']['vBulletin3']['licenseKey'] = 'LXXXXXXX';
 
+// ###################################################################
+// Invision Power Board 2 configuration
+
+/**
+ * Database table prefix
+ */
+$config['auth']['IPB2']['tablePrefix'] = 'ibf_';
+
+/**
+ * Cookie prefix
+ */
+$config['auth']['IPB2']['cookiePrefix'] = '';
+
 ?>
\ No newline at end of file