When calling BSFunctions::cookie() to clear cookies, we need FALSE not NULL
[bugdar.git] / includes / auth / auth_vbulletin.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Bugdar
5 || # Copyright ©2002-2007 Blue Static
6 || #
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.
10 || #
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
14 || # more details.
15 || #
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 \*=====================================================================*/
21
22 require_once('./includes/auth/auth.php');
23
24 /**
25 * Authentication: vBulletin
26 *
27 * This is used to authenticate against the vBulletin user database. It
28 * does NOT use the vBulletin permission system, however. Be sure you set
29 * all the database variables and your license key.
30 *
31 * @author Blue Static
32 * @copyright Copyright (c)2002 - 2007, Blue Static
33 * @version $Revision$
34 * @package Bugdar
35 *
36 */
37 class AuthenticationVbulletin extends Authentication
38 {
39 /**
40 * This is the vBulletin license key that you can find in the Members' Area that is used in creating cookies
41 * @var string
42 */
43 var $licenseKey = 'LXXXXXXX';
44
45 /**
46 * The table prefix for all of vBulletin's tables
47 * @var string
48 */
49 var $vBTablePrefix = '';
50
51 /**
52 * Fields that map Bugdar fields to vBulletin fields
53 * @var string
54 */
55 var $fieldMap = array(
56 'authid' => 'userid',
57 'email' => 'email',
58 'timezone' => 'timezoneoffset',
59 'displayname' => 'username'
60 );
61
62 // ###################################################################
63 function _setupDatabase()
64 {
65 $this->authDb = new BSDbMySqlI($this->registry);
66 $this->authDb->connect('VBULLETIN_DATABASE_SERVER', 'VB_DATABASE_USER', 'VB_DATABASE_PASSWORD', 'VBULLETIN_DATABASE_NAME');
67 }
68
69 // ###################################################################
70 function _fetchCookieUniqueId()
71 {
72 return BSApp::$input->inputClean('bbuserid', TYPE_UINT);
73 }
74
75 // ###################################################################
76 function _fetchCookiePassword()
77 {
78 return BSApp::$input->in['bbpassword'];
79 }
80
81 // ###################################################################
82 function _fetchUserUsingCookies()
83 {
84 return $this->authDb->queryFirst("SELECT * FROM {$this->vBTablePrefix}user WHERE userid = " . $this->_fetchCookieUniqueId());
85 }
86
87 // ###################################################################
88 function _verifyCookieData()
89 {
90 return (md5($this->authUser['password'] . $this->licenseKey) == $this->_fetchCookiePassword());
91 }
92
93 // ###################################################################
94 function _setCookies($sticky = false)
95 {
96 BSFunctions::cookie('bbuserid', $this->authUser['userid'], $sticky);
97 BSFunctions::cookie('bbpassword', md5($this->authUser['password'] . $this->licenseKey), $sticky);
98 }
99
100 // ###################################################################
101 function clearCookies()
102 {
103 BSFunctions::cookie('bbpassword', false);
104 BSFunctions::cookie('bbuserid', false);
105 }
106
107 // ###################################################################
108 function _fetchUserWithIdentifier($username)
109 {
110 return $this->authDb->queryFirst("SELECT * FROM {$this->vBTablePrefix}user WHERE username = '" . $this->authDb->escapeString($username) . "'");
111 }
112
113 // ###################################################################
114 function _verifyLoginUser($password)
115 {
116 return ($this->authUser['password'] == md5(md5($password) . $this->authUser['salt']));
117 }
118 }
119
120 /*=====================================================================*\
121 || ###################################################################
122 || # $HeadURL$
123 || # $Id$
124 || ###################################################################
125 \*=====================================================================*/
126 ?>