Log in

View Full Version : Easier vBulletin Integration


Scott MacVicar
11-05-2002, 10:11 PM
As so many people are asking about integration with a product heres a quick class i whipped up to check the password.

class forum {

var $database = '';

function check_password ($username='', $userid=0, $password, $md5=0) {
if ($userid == 0) {
$query = mysql_query("SELECT * FROM " . $this->database . ".user WHERE username='".addslashes($username)."'");
} else {
$query = mysql_query("SELECT * FROM " . $this->database . ".user WHERE userid='".intval($userid)."'");
}
$user = mysql_fetch_array($query);
if ($md5) {
if ($password == $user['password']) {
return true;
} else {
return false;
}
} else {
if (md5($password) == $user['password']) {
return true;
} else {
return false;
}
}
}

}

usage
/*usage
$object->check_password(USERNAME, USERID, PASSWORD, MD5)
username is the username of password to check
userid is the userid of the user you can use either of these

password is the password either in md5 or unhashed
md5 set this to 1 if the password you are putting into the function has already been hashed
*/

require_once('./forum_class.php');
$forum = new forum;
$forum->database = 'vbulletin_development';

//username method
if ($forum->check_password($_POST['username'], '', $_POST['password'])) {
echo 'password matches';
} else {
echo 'no access';
}

//userid method
if ($forum->check_password('', $_COOKIE['bbuserid'], $_COOKIE['bbpassword'], 1)) {
echo 'password matches';
} else {
echo 'no access';
}

though it does presume an active connection to the database has already been made by some aspect of the script.

Hopefully this will help someone.

Dean C
11-07-2002, 05:17 PM
Sounds good Scott :)

- miSt

TECK
11-11-2002, 09:20 PM
sounds more then good...

Scott MacVicar
11-11-2002, 09:34 PM
and it also means that if you change forum software (not that you would want to) or upgrade to say v3 you dont have to go through and edit every single file, only the file witt this class in it.

ConKien
03-29-2006, 10:23 PM
Can this work for vb3.5.x Scott?