]>
src.bluestatic.org Git - bugdar.git/blob - includes/auth/auth_phpbb2.php
2 /*=====================================================================*\
3 || ###################################################################
5 || # Copyright (c)2004-2009 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()
62 parent
::_setupDatabase();
64 include 'includes/auth/config.php';
65 $this->phpBBTablePrefix
= $config['auth']['phpBB2']['tablePrefix'];
66 $this->cookieName
= $config['auth']['phpBB2']['cookieName'];
69 // ###################################################################
70 function _fetchCookieUniqueId()
72 $val = BSApp
::$input->in
[$this->cookieName
. '_sid'];
73 return (!$val ? -1 : $val); // hack so we don't do stupid things but can still create a session
76 // ###################################################################
77 function _fetchCookiePassword()
82 // ###################################################################
83 function _fetchUserUsingCookies()
85 $session = $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb
->escapeString($this->_fetchCookieUniqueId()) . "'");
88 // phpBB's wacky auto-login system
89 $data = unserialize($_COOKIE[$this->cookieName
. '_data']);
94 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']) . "'");
98 if ($session['session_user_id'] == 0 OR $session['session_user_id'] == -1)
102 return $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE user_id = " . $session['session_user_id']);
106 // ###################################################################
107 function _verifyCookieData()
109 return ($this->_fetchUserUsingCookies() != false);
112 // ###################################################################
113 function _fetchUserWithIdentifier($string)
115 return $this->authDb
->queryFirst("SELECT * FROM {$this->phpBBTablePrefix}users WHERE username = '" . $this->authDb
->escapeString($string) . "'");
118 // ###################################################################
119 function _verifyLoginUser($password)
121 return (md5($password) == $this->authUser
['user_password']);
124 // ###################################################################
125 function clearCookies()
127 BSFunctions
::cookie($this->cookieName
. '_data');
128 BSFunctions
::cookie($this->cookieName
. '_sid');
129 $this->authDb
->query("DELETE FROM {$this->phpBBTablePrefix}sessions WHERE session_id = '" . $this->authDb
->escapeString($this->_fetchCookieUniqueId()) . "'");
132 // ###################################################################
133 function _setCookies($permanent = false)
135 $sid = $this->_fetchCookieUniqueId();
136 $sid = ($sid != '-1' ? $sid : md5(microtime() . rand()));
137 BSFunctions
::cookie($this->cookieName
. '_sid', $sid, false);
140 BSFunctions
::cookie($this->cookieName
. '_data', serialize(array('autologinid' => $this->authUser
['user_password'], 'userid' => $this->authUser
['user_id'])), true);
142 $this->authDb
->query("
143 REPLACE INTO {$this->phpBBTablePrefix}sessions
144 (session_id, session_user_id, session_start, session_time, session_logged_in)
147 '$sid', " . $this->authUser
['user_id'] . ", " . time() . ", " . time() . ", 1
151 $this->authDb
->query("UPDATE {$this->phpBBTablePrefix}users SET user_session_time = " . time() . ", user_lastvisit = " . time() . " WHERE user_id = " . $this->authUser
['user_id']);