--- /dev/null
+<?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