r1424: Add the initial authentication system for vBulletin
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 27 Feb 2007 03:22:26 +0000 (03:22 +0000)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 27 Feb 2007 03:22:26 +0000 (03:22 +0000)
includes/auth/auth_vbulletin.php [new file with mode: 0644]

diff --git a/includes/auth/auth_vbulletin.php b/includes/auth/auth_vbulletin.php
new file mode 100644 (file)
index 0000000..ca36d79
--- /dev/null
@@ -0,0 +1,140 @@
+<?php
+/*=====================================================================*\
+|| ###################################################################
+|| # Bugdar [#]version[#]
+|| # Copyright ©2002-[#]year[#] Blue Static
+|| #
+|| # This program is free software; you can redistribute it and/or modify
+|| # it under the terms of the GNU General Public License as published by
+|| # the Free Software Foundation; version [#]gpl[#] of the License.
+|| #
+|| # This program is distributed in the hope that it will be useful, but
+|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+|| # more details.
+|| #
+|| # You should have received a copy of the GNU General Public License along
+|| # with this program; if not, write to the Free Software Foundation, Inc.,
+|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
+|| ###################################################################
+\*=====================================================================*/
+
+require_once('./includes/auth/auth.php');
+
+/**
+* Authentication: vBulletin
+*
+* This is used to authenticate against the vBulletin user database. It
+* does NOT use the vBulletin permission system, however. Be sure you set
+* all the database variables and your license key.
+*
+* @author              Blue Static
+* @copyright   Copyright (c)2002 - [#]year[#], Blue Static
+* @version             $Revision$
+* @package             Bugdar
+*
+*/
+class AuthenticationVbulletin extends Authentication
+{
+       /**
+       * This is the vBulletin license key that you can find in the Members' Area that is used in creating cookies
+       * @var string
+       */
+       var $licenseKey = 'LXXXXXX';
+       
+       /**
+       * The table prefix for all of vBulletin's tables
+       * @var string
+       */
+       var $vBTablePrefix = '';
+       
+       // ###################################################################
+       function _setupDatabase()
+       {
+               $this->authDb =& new DB_MySQL($this->registry);
+               $this->authDb->connect('VBULLETIN_DATABASE_SERVER', 'VB_DATABASE_USER', 'VB_DATABASE_PASSWORD', 'VBULLETIN_DATABASE_NAME', false);
+       }
+       
+       // ###################################################################
+       function _fetchCookieUniqueId()
+       {
+               return $this->registry->input_clean('bbuserid', TYPE_UINT);
+       }
+       
+       // ###################################################################
+       function _fetchCookiePassword()
+       {
+               return $this->registry->in['bbpassword'];
+       }
+       
+       // ###################################################################
+       function _fetchUserUsingCookies()
+       {
+               return $this->authDb->query_first("SELECT * FROM {$this->vBTablePrefix}user WHERE userid = " . $this->_fetchCookieUniqueId());
+       }
+       
+       // ###################################################################
+       function _verifyCookieData()
+       {
+               return (md5($this->authUser['password'] . $this->licenseKey) == $this->_fetchCookiePassword());
+       }
+       
+       // ###################################################################
+       function _setCookies($sticky = false)
+       {
+               $this->registry->funct->cookie('bbuserid', $this->authUser['userid'], $sticky);
+       $this->registry->funct->cookie('bbpassword', md5($this->authUser['password'] . $this->licenseKey), $sticky);
+       }
+       
+       // ###################################################################
+       function _clearCookies()
+       {
+               $this->registry->funct->cookie('bbpassword');
+               $this->registry->funct->cookie('bbuserid');
+       }
+       
+       // ###################################################################
+       function _fetchBugdarUserFromAuthUser()
+       {
+               $user = $this->db->query_first("SELECT * FROM " . TABLE_PREFIX . "user WHERE authid = " . $this->authUser['userid']);
+               if (!$user)
+               {
+                       return $this->_createBugdarUser();
+               }
+               return $user;
+       }
+       
+       // ###################################################################
+       function _createBugdarUser()
+       {
+               $user = new UserAPI($this->registry); // do not change this
+               $user->set('email', $this->authUser['email']);
+               $user->set('displayname', $this->authUser['name']);
+               $user->set('password', $this->authUser['password']); // some random value that won't be used for authentication
+               $user->set('usergroupid', 2); // default "Registered Users" group
+               $user->set('authid', $this->authUser['userid']); // This must be a COMPLETELY STATIC key that is found in the auth db that will permanently link Bugdar to the auth user
+               $user->insert(); // saves the user
+               
+               return $user->values; // returns the newly created user array
+       }
+       
+       // ###################################################################
+       function _fetchUserWithIdentifier($username)
+       {
+               return $this->authDb->query_first("SELECT * FROM {$this->vBTablePrefix}user WHERE username = '" . $this->authDb->escape_string($username) . "'");
+       }
+       
+       // ###################################################################
+       function _verifyLoginUser($password)
+       {
+               return ($this->authUser['password'] == md5(md5($password) . $this->authUser['salt']));
+       }
+}
+
+/*=====================================================================*\
+|| ###################################################################
+|| # $HeadURL$
+|| # $Id$
+|| ###################################################################
+\*=====================================================================*/
+?>
\ No newline at end of file