Technology TidBits

Answers to various technical questions on php programming, mysql, linux, and many more categories.
25% off Hosting at HostGator.com:
Use Code techbits25



How can I authenticate a user in my vbulletin database from a php script?

Last updated: 02/08/2012

Here's a php snippet that connects to your vbulletin database and checks a username / password against it.  This is useful for having other scripts on your site authenticate users against the same registered user list as vbulletin.

<?

$host = "hostname";
$user = "username";
$pass = "password";
$db = "database";

$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db, $conn);
$sql = "SELECT userid, usergroupid, membergroupids, infractiongroupids, username, password, salt FROM vb_user WHERE username = '" . htmlspecialchars($username). "'";

$r = mysql_query($sql,$conn);
$results = mysql_fetch_array($r, MYSQL_ASSOC);

mysql_free_result($r);

if($results['password'] != '' && $results['password'] == md5(md5($password).$results['salt'])) {
 // this is a match
}
else {
 // this is not a match
}
?>

blog comments powered by Disqus
Have your own Tech-bit to contribute? Submit it here

Other questions in this category:
How can I change the colors of my forums using vBulletin 4 ?
How can I tie into my vbulletin user database from a perl script?
How can I get vBulletin configured on a 1&1 Managed server?



Powered by KnowledgebasePublisher 1.1
Host Gator
Content provided by Roberts WebForge, Inc.