WordPress: Easily Reset Your Account Password Using MySQL and PHP
Posted on 08. Jun, 2009 by Dragos in Coding, MySQL, PHP
I’ve just forgot my admin password on my local testing blog, and what is worse – my local machine is not configured to send external email. Oh yeah, got to reinstall wordpress again, what a pity. No way! There are two ways of resetting your password using two easy methods. You’ll need basic knowledge of PHP or CPanel+PHPMyAdmin.
I Method: CPanel+PHPMyAdmin
For this method, it is necessary that your host have CPanel and PHPMyAdmin installed. If your host doesn’t have these pieces of software, but something similar to these, you can follow this tutorial and apply these steps to your situation.
First we’ll need to open the PHPMyAdmin page. From the CPanel root page, launch PHPMyAdmin. The icon of PHPMyAdmin should look similar to the one emphasized in the screenshot below.
Once on the main page of PHPMyAdmin you should remember what database did you use when installing wordpress. If you don’t remember, don’t get angry. Go to your root folder where wordpress is installed and download & open the file wp-config.php with a simple text editor like Notepad/GEdit. You’ll need to find this line:
define('DB_NAME', 'ABCD');
Note that ABCD (without the single quotes around it) is the name of the database that wordpress is installed in.
Back on the PHPMyAdmin page, click on the link of your database name. In my case it was _iwebdevel.
Now you’ll see another PHPMyAdmin page, but this time you’ll be presented all your tables contained in the ABCD database. We need to select the table users. You won’t see the exact name users of this table, but a name in this format xx_users , where xx_ is the prefix of your wordpress table names. Click on the link of your users table (xx_users). In my case, as in most cases it’s wp_users:
Now click on browse to see the rows contained in table xx_users.
Now look for the username you want to reset the password. In my case I want to reset password for admin. Now click on the edit button.
Now you’ll need to generate an MD5 hash of the new password you would like to set. Go to http://seoanalytic.com/tools/md5_encryptor/ and enter your preferred password. After you enter your new password, click on the Encrypt! button.
After you’ve encrypted your password, select and copy the newly MD5 generated hash code.
Now return to your PHPMyAdmin page and paste your MD5 hash from the clipboard to the input field as shown in the image below:
Finally click on Go button to save your new password.
II Method: PHP
In my opinion the second method is much faster and simpler. In this method you’ll just have to upload a PHP file to your host and access it with a browser. But we’ll talk about it a little bit later.
So here’s the piece of PHP code I’ve came up with to help you reset your wordpress account password.
$newPassword='NEW_PASSWORD_GOES_HERE'; //put your new password between the single quotes
$username='admin'; //put the login username you'd like to change the password to
@include_once('./wp-config.php'); //get some details from your wordpress installation
global $table_prefix;
$conxb=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD); //establish connection to your database
mysql_select_db(DB_NAME,$conxb);
$query='update `'.$table_prefix.'users` set `user_pass`=\''.mysql_real_escape_string(md5($newPassword)).'\' where `user_login`=\''.mysql_real_escape_string($username).'\' limit 1';
$mQuery=mysql_query($query,$conxb); //set new password
echo $mQuery?'Successfully set new password. New password: '.$newPassword:'There was an error. Error: '.mysql_error(); //if result is unsuccessful you'll see the mysql error message
mysql_close($conxb);
For your convenience you can download the file reset.php from here.
Now extract the zip archive you’ve just downloaded and edit the necessary parameters to suit your needs (explanation comments are present in the PHP code above). Then upload the file reset.php to your wordpress root installation folder. To make sure that this is the right directory, look for a file named wp-config.php, if it’s there you’re on the right way, else look for the directory where wp-config.php is present and upload the file reset.php there.
Finally you’ll want to go to http://yourDomainName.TLD/reset.php . You’ll see the appropriate message depending on how the script worked. If there is an error, post it here and I’ll try to help you, else you did everything perfectly and you can now log in with your new password.
Related posts:
- SQLite, MySQL, PHP: Ternary operator (IF() statement) in MySQL and SQLite
- WordPress 2.8.4: Not ready to be installed with PHP 5.3 ?
- WordPress: Best SEO iTranslator for WordPress, get free traffic from fully automated plugin script
- WordPress: Version 2.8.6 is out. Make sure to update your blog!
- PHP: How to get creation time of file with PHP on Linux machines
-
purie
-
Katya



















































