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 tie into my vbulletin user database from a perl script?

Last updated: 02/08/2012

Sometimes you may want to verify a username / password matches up to a valid vbulletin user, from a perl script.  Here's a snippet of code to query the vbulletin database and test the user:

  use Digest::MD5 qw(md5_hex);
  use DBI;
  my $db_user = "dbuser";
  my $db_pass = "pass";
  my $dsn = "DBI:mysql:DBNAME:HOSTNAME";

   $dbh = DBI->connect($dsn, $db_user, $db_pass);

   my $sql = "SELECT userid, usergroupid, membergroupids, infractiongroupids, username, password, salt FROM vb_user WHERE username = '" . $form{'uname'}. "'";
  my $sth = $dbh->prepare ($sql);
  $sth->execute();
  my $h_ref = $sth->fetchrow_hashref();
  $sth->finish();
  if($h_ref->{'password'} != '' && $h_ref->{'password'} eq md5_hex(md5_hex($form{'upw'}).$h_ref->{'salt'})) {
   # This matches

} else {

 # 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 authenticate a user in my vbulletin database from a php 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.