3 * External authentication with a vBulletin database.
5 * Copyright © 2009 Aryeh Gregor
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; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 * http://www.gnu.org/copyleft/gpl.html
26 * This class supports the proprietary vBulletin forum system
27 * <http://www.vbulletin.com>, versions 3.5 and up. It calls no functions or
28 * code, only reads from the database. Example lines to put in
31 * $wgExternalAuthType = 'ExternalUser_vB';
32 * $wgExternalAuthConf = array(
33 * 'server' => 'localhost',
34 * 'username' => 'forum',
35 * 'password' => 'udE,jSqDJ<""p=fI.K9',
36 * 'dbname' => 'forum',
37 * 'tablePrefix' => '',
38 * 'cookieprefix' => 'bb'
41 * @ingroup ExternalUser
43 class ExternalUser_vB
extends ExternalUser
{
46 protected function initFromName( $name ) {
47 return $this->initFromCond( array( 'username' => $name ) );
50 protected function initFromId( $id ) {
51 return $this->initFromCond( array( 'userid' => $id ) );
54 protected function initFromCookie() {
55 # Try using the session table. It will only have a row if the user has
56 # an active session, so it might not always work, but it's a lot easier
57 # than trying to convince PHP to give us vB's $_SESSION.
58 global $wgExternalAuthConf, $wgRequest;
59 if ( !isset( $wgExternalAuthConf['cookieprefix'] ) ) {
62 $prefix = $wgExternalAuthConf['cookieprefix'];
64 if ( $wgRequest->getCookie( 'sessionhash', $prefix ) === null ) {
70 $row = $db->selectRow(
71 array( 'session', 'user' ),
74 'session.userid = user.userid',
75 'sessionhash' => $wgRequest->getCookie( 'sessionhash', $prefix ),
87 private function initFromCond( $cond ) {
90 $row = $db->selectRow(
104 private function getDb() {
105 global $wgExternalAuthConf;
106 return DatabaseBase
::factory( 'mysql',
108 'host' => $wgExternalAuthConf['server'],
109 'user' => $wgExternalAuthConf['username'],
110 'password' => $wgExternalAuthConf['password'],
111 'dbname' => $wgExternalAuthConf['dbname'],
112 'tablePrefix' => $wgExternalAuthConf['tablePrefix'],
117 private function getFields() {
118 return array( 'user.userid', 'username', 'password', 'salt', 'email',
119 'usergroupid', 'membergroupids' );
122 public function getId() { return $this->mRow
->userid
; }
123 public function getName() { return $this->mRow
->username
; }
125 public function authenticate( $password ) {
126 # vBulletin seemingly strips whitespace from passwords
127 $password = trim( $password );
128 return $this->mRow
->password
== md5( md5( $password )
129 . $this->mRow
->salt
);
132 public function getPref( $pref ) {
133 if ( $pref == 'emailaddress' && $this->mRow
->email
) {
134 # TODO: only return if validated?
135 return $this->mRow
->email
;
140 public function getGroups() {
141 $groups = array( $this->mRow
->usergroupid
);
142 $groups = array_merge( $groups, explode( ',', $this->mRow
->membergroupids
) );
143 $groups = array_unique( $groups );