]>
src.bluestatic.org Git - bugdar.git/blob - includes/auth/auth_phpbb2.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright ©2002-2007 Blue Static
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version 2 of the License.
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
22 require_once('./includes/auth/auth.php');
25 * Authentication: phpBB2
27 * Authentication system for phpBB2
30 * @copyright Copyright (c)2002 - 2007, Blue Static
35 class AuthenticationPhpbb2
extends Authentication
38 * Mapping of Bugdar to phpBB2 fields
41 var $fieldMap = array(
42 'authid' => 'user_id',
43 'displayname' => 'username',
44 'email' => 'user_email'
48 * Database table prefix
51 var $phpBBTablePrefix = 'phpbb2_';
54 * The cookie name that is set in phpBB -> Administration -> General Admin -> Configuration -> Cookie Settings -> Cookie Name
57 var $cookieName = 'phpbb2mysql';
59 // ###################################################################
60 function _setupDatabase()
63 $this->authDb
= new BSDbMySQLI($this->registry
);
64 $this->authDb
->connect('DATABASE_SERVER', 'DATABASE_USER', 'DATABASE_PASSWORD', 'DATABASE_NAME');
67 // ###################################################################
68 function _fetchCookieUniqueId()
70 $val = BSApp
::$input->in
[$this->cookieName
. '_sid'];
71 return (!$val ? -1 : $val); // hack so we don't do stupid things but can still create a session
74 // ###################################################################
75 function _fetchCookiePassword()
80 // ###################################################################
81 function _fetchUserUsingCookies()
83 $session = $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb
->escapeString($this->_fetchCookieUniqueId()) . "'");
86 // phpBB's wacky auto-login system
87 $data = unserialize($_COOKIE[$this->cookieName
. '_data']);
92 return $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . BSApp
::$input->clean($data['userid'], TYPE_UINT
) . " AND user_password = '" . $this->authDb
->escapeString($data['autologinid']) . "'");
96 if ($session['session_user_id'] == 0 OR $session['session_user_id'] == -1)
100 return $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . $session['session_user_id']);
104 // ###################################################################
105 function _verifyCookieData()
107 return ($this->_fetchUserUsingCookies() != false);
110 // ###################################################################
111 function _fetchUserWithIdentifier($string)
113 return $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE username = '" . $this->authDb
->escapeString($string) . "'");
116 // ###################################################################
117 function _verifyLoginUser($password)
119 return (md5($password) == $this->authUser
['user_password']);
122 // ###################################################################
123 function clearCookies()
125 BSFunctions
::cookie($this->cookieName
. '_data');
126 BSFunctions
::cookie($this->cookieName
. '_sid');
127 $this->authDb
->query("DELETE FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb
->escapeString($this->_fetchCookieUniqueId()) . "'");
130 // ###################################################################
131 function _setCookies($permanent = false)
133 $sid = $this->_fetchCookieUniqueId();
134 $sid = ($sid != '-1' ? $sid : md5(microtime() . rand()));
135 BSFunctions
::cookie($this->cookieName
. '_sid', $sid, false);
138 BSFunctions
::cookie($this->cookieName
. '_data', serialize(array('autologinid' => $this->authUser
['user_password'], 'userid' => $this->authUser
['user_id'])), true);
140 $this->authDb
->query("
141 REPLACE INTO {$this->phpBBTablePrefix}sessions
142 (session_id, session_user_id, session_start, session_time, session_logged_in)
145 '$sid', " . $this->authUser
['user_id'] . ", " . time() . ", " . time() . ", 1
149 $this->authDb
->query("UPDATE {$this->phpBBTablePrefix}users SET user_session_time = " . time() . ", user_lastvisit = " . time() . " WHERE user_id = " . $this->authUser
['user_id']);
153 /*=====================================================================*\
154 || ###################################################################
157 || ###################################################################
158 \*=====================================================================*/