3 # Copyright (C) 2009 Aryeh Gregor
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License along
16 # with this program; if not, write to the Free Software Foundation, Inc.,
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 # http://www.gnu.org/copyleft/gpl.html
21 * This class supports the proprietary vBulletin forum system
22 * <http://www.vbulletin.com>, versions 3.5 and up. It calls no functions or
23 * code, only reads from the database. Example lines to put in
26 * $wgExternalAuthType = 'ExternalUser_vB';
27 * $wgExternalAuthConf = array(
28 * 'server' => 'localhost',
29 * 'username' => 'forum',
30 * 'password' => 'udE,jSqDJ<""p=fI.K9',
31 * 'dbname' => 'forum',
32 * 'tableprefix' => '',
33 * 'cookieprefix' => 'bb'
36 * @ingroup ExternalUser
38 class ExternalUser_vB
extends ExternalUser
{
41 protected function initFromName( $name ) {
42 return $this->initFromCond( array( 'username' => $name ) );
45 protected function initFromId( $id ) {
46 return $this->initFromCond( array( 'userid' => $id ) );
49 protected function initFromCookie() {
50 # Try using the session table. It will only have a row if the user has
51 # an active session, so it might not always work, but it's a lot easier
52 # than trying to convince PHP to give us vB's $_SESSION.
53 global $wgExternalAuthConf;
54 if ( !isset( $wgExternalAuthConf['cookieprefix'] ) ) {
57 $prefix = $wgExternalAuthConf['cookieprefix'];
59 if ( !isset( $_COOKIE["{$prefix}sessionhash"] ) ) {
65 $row = $db->selectRow(
66 array( 'session', 'user' ),
69 'session.userid = user.userid',
70 'sessionhash' => $_COOKIE["{$prefix}sessionhash"]
82 private function initFromCond( $cond ) {
85 $row = $db->selectRow(
99 private function getDb() {
100 global $wgExternalAuthConf;
102 $wgExternalAuthConf['server'],
103 $wgExternalAuthConf['username'],
104 $wgExternalAuthConf['password'],
105 $wgExternalAuthConf['dbname'],
107 $wgExternalAuthConf['tableprefix']
111 private function getFields() {
112 return array( 'user.userid', 'username', 'password', 'salt', 'email',
113 'usergroupid', 'membergroupids' );
116 public function getId() { return $this->mRow
->userid
; }
117 public function getName() { return $this->mRow
->username
; }
119 public function authenticate( $password ) {
120 # vBulletin seemingly strips whitespace from passwords
121 $password = trim( $password );
122 return $this->mRow
->password
== md5( md5( $password )
123 . $this->mRow
->salt
);
126 public function getPref( $pref ) {
127 if ( $pref == 'emailaddress' && $this->mRow
->email
) {
128 # TODO: only return if validated?
129 return $this->mRow
->email
;
134 public function getGroups() {
135 $groups = array( $this->mRow
->usergroupid
);
136 $groups = array_merge( $groups, explode( ',', $this->mRow
->membergroupids
) );
137 $groups = array_unique( $groups );