Features

How to issue new passwords in vBulletin

How to issue new passwords in vBulletin

Copyright © TechPad.co.uk

If your vBulletin site has been the subject of intrusion it's a wise precaution to reissue passwords to your users. Here's how to change all of the passwords in vBulletin 3.

The vBulletin forum software stores the user's password as an encrypted hash in the database, along with a unique salt for each user. Therefore,

1. Setup your configuration

At the top of your script, add the following section to make some constants we can use in our database connection functions. 

if(!defined('HOSTNAME'))define('HOSTNAME','localhost');
if(!defined('USERNAME'))define('USERNAME','usernamehere');
if(!defined('PASSWORD'))define('PASSWORD','passwordhere');
if(!defined('DATABASE'))define('DATABASE','databasehere');
 

2. Add a random password function

In order to create new passwords for your users you'll need a little function to create a random password. You can use anything you like for this. This is the one I used, which allows you to set the length and the complexity of the password when the function is called. 


function generatePassword($length=9, $strength=0) {
    $vowels = 'aeuy';
    $consonants = 'bdghjmnpqrstvz';
    if ($strength & 1) {
        $consonants .= 'BDGHJLMNPQRSTVWXZ';
    }
    if ($strength & 2) {
        $vowels .= "AEUY";
    }
    if ($strength & 4) {
        $consonants .= '23456789';
    }
    if ($strength & 8) {
        $consonants .= '@#$%';
    }
 
    $password = '';
    $alt = time() % 2;
    for ($i = 0; $i < $length; $i++) {
        if ($alt == 1) {
            $password .= $consonants[(rand() % strlen($consonants))];
            $alt = 0;
        } else {
            $password .= $vowels[(rand() % strlen($vowels))];
            $alt = 1;
        }
    }
    return $password;
}

3. Connect to the database

Next, you'll need to connect to the server and select the vBulletin database. We're using the constants we created earlier on in this script. 

mysql_pconnect(HOSTNAME,USERNAME,PASSWORD) or die("Could not connect to server");
mysql_select_db(DATABASE) or die("Could not select database");

4. Select the data

Now you're connected you'll need to select the userid, username, password and salt. The salt is unique to each user, so we need this to ensure the password we create works for them. This is the first chunk of code.


$query = "SELECT userid, username, password,salt FROM user ORDER BY userid";
$result = mysql_query($query);

while($row = mysql_fetch_array($result)){

    // Fetch user's old password
    $userid = stripslashes($row['userid']);
    $username = stripslashes($row['username']);
    $password = stripslashes($row['password']);
    $salt = $row['salt'];

5. Now, generate the new password

In vBulletin a user's password is encrypted with md5 encryption (twice) and the user's salt. Here we're running our function to generate a password with a length of nine characters and a complexity of eight, and then encrypting it with md5 and the user's specific salt, then encrypting that. 

    // Generate a new password hash using the user's salt
    $generated_password = generatePassword("9","8");
    $generated_hash = md5(md5($generated_password).$salt);

6. Update the database

To finish off the script, we now need to add the new password and hash to the database. I created (temporarily) a couple of fields to store these data in, then populated them by running the script. You can then export the temporary passwords and email them to your users. 

    // Update the user table with the new details
    $update_query = "UPDATE `user` SET
    `temp_pwd` = '$generated_password',
    `temp_hash` = '$generated_hash'
    WHERE `userid` = $userid LIMIT 1";

    $update_result = mysql_query($update_query) or die(mysql_error());
   
    echo "$update_query
";

}

7. Cleaning up

When you've done that, and exported the new passwords to your users so they can login, you can then delete the old password column and replace it with the new temp_hash column and then drop the temp_pwd column. As this is not encrypted, you wouldn't want to leave it sitting around on your server. 

It's a wise precaution to test that the new passwords work prior to deleting the columns! If the login fails, the user can request a password reset and they'll be sent instructions to reset. 



Published: TechPad.co.uk Monday 1 March 2010, 7:11 pm
Views: 735 times
Filed under: vBulletin security password reset

(No votes yet)



Login to leave your comments

Please login

Username
Password
  Remember me
Reset password | Send activation code

Related items

Protecting against SQL injection and XSS attacks in PHP
Protecting against SQL injection and XSS attacks in PHP
Learn how to write PHP code that is protec... 5 (1 vote)
Create an encrypted USB drive for Ubuntu Linux
Create an encrypted USB drive for Ubuntu Linux
Protect the sensitive data on your USB key... no votes (No votes) *1 comment

Recently added

How to create a Linux iPlayer download GUI using Zenity
How to create a Linux iPlayer download GUI using Zenity
Here's how I created a simple graphical ut... no votes (No votes)
A taste of iPhone support coming in Ubuntu Lucid Lynx
A taste of iPhone support coming in Ubuntu Lucid Lynx
Ubuntu's Lucid Lynx release, which comes o... no votes (No votes)
Frequently asked questions on NexentaCore
Frequently asked questions on NexentaCore
Frequently asked questions about NexentaCo... no votes (No votes)
Create a video transcoder GUI with Zenity and ffmpeg
Create a video transcoder GUI with Zenity and ffmpeg
Create a GUI application for your Linux co... 4 (1 vote)

Most viewed


Recent comments


Analytics sites

Analytics for Marketers
Analytics for Marketers
A companion site for the bo...
Excellent Analytics free Excel plugin
Excellent Analytics free Excel plugin
Excellent Analytics is a si...
Web Analytics 2.0
Web Analytics 2.0
Probably the best and most ...