How to Reset a WordPress Password From the Database
At times when we cannot access our dashboard due to either forgetting or getting our password changed by someone else, it is good to have alternative ways of altering it. There are multitudes of methods to reset or change a password for your user’s login into the WordPress dashboard. These include the ‘Lost your password?’ link on the login page, the automatic emailer, via FTP and many more. There are even two different ways of changing a password through phpMyAdmin alone, that is by using a MySQL command line, and through editing the “users” table within phpMyAdmin options. In this article, we will cover both methods for changing the user’s password from the database.
Accessing Your Database
In order to start editing anything, naturally, we will first need to access it. To access the database, if you’re working on a live server, you will either have to contact your hosting provider, or access your cPanel and navigate to phpMyAdmin.
If you’re working on a local server you can go to the designated dashboard for it, we will be using the XAMPP control panel, and press the admin button for MySQL.
Once you have done any of these you will be redirected to the phpMyAdmin dashboard page on your default browser.
On the left-hand side of the page, you will see a list of your databases. Choose the one to which you are trying to log in by simply clicking on it. Once you choose the database you’d like edited you should see the overview of its tables. To change a password for a user, you will need to access the ‘users’ table.
Don’t be discouraged if the prefix for the tables is different. WordPress sets wp_ as the default but there are a few ways to change this table prefix within your database.
The important part now, when it comes to changing the password, is that you select the ‘users’ table by clicking either its name or the Browse link within that row.
You should be taken to the ‘users’ table overview that looks something like this:
If you have more users on your website, naturally, there will be more rows within the table.
The password column can be edited from here by simply double-clicking the field, however, this represents the encoded version of the password and the browser will not recognize it as the same password if you simply typed in for example “4dm1n”.
The subsequent steps for changing the password will vary depending on whether you’d like to use SQL code through the MySQL command line to alter the tables or you prefer doing that by hand through phpMyAdmin data table options.
How to Reset WordPress Password using MySQL Command Line
Now that you are situated within the database that you’d like to edit and its “users” table, click the SQL tab shown near the top of the browser window.
A new form should be presented with a text area where you can replace the existing line of code:
SELECT * FROM `wp_users` WHERE 1
with the following line of code
UPDATE `wp_users` SET `user_pass`= MD5('yourpassword') WHERE `user_login`='yourusername';
Please make sure to backup your database before continuing any further since a mistake within the code can cause an unexpected database error. Also, make sure to leave the single quotes as in the example of the code above, otherwise, the code will not work. Lastly, please make sure you leave the password within the MD5 brackets since the MD5 setting uses one of WordPress’ early encoding algorithms that has since been replaced, and because of this, the first time you attempt to log in WordPress will use a newer encryption algorithm on the password you entered preserving it for use as if you have set it up from the WordPress registration page.
Now, once you have switched out the ‘yourusername’ with the user name of the user you’re changing the password to, and ‘yourpassword’ with the password you’d like to use in the future, you should click the GO button in the lower right corner.
This code, once run, will search, within the “users” table, for the username that you input and replace that user’s password with the one that you chose. If this action was successful you should get a green bar near the top of the screen indicating that exactly one row has been affected by this action.
Now you can navigate to your login page and use the newly changed password for the, in this example, “admin” user.
How to Reset a WordPress Admin Password from phpMyAdmin
If, however, you’d like to change the password manually you should locate the user you’d like to change the password for, and click the edit link next to the pencil icon.
Once you have done this a form will show up that will allow you to set and edit various fields pertaining to the user. One of which is the user_pass field which we will be looking to edit.
As you can see in the image above, we have changed the value of the function dropdown in the user_pass row to MD5. Then we added the password we want to use for accessing the dashboard in the text field next to it.
The reason we had to change the function dropdown is precisely the password encoding we mentioned previously. As previously noted, the MD5 setting uses one of WordPress’ early encoding algorithms that has since been replaced, because of this, the first time you attempt to log in WordPress will use a newer encryption algorithm on the password you entered preserving it for use as if you have set it up from the WordPress registration page.
This concludes the steps needed to change your password via the phpMyAdmin and by using SQL code within the database. We hope that by using this guide you will be able to restore control over your installation and not lose the valuable hours spent on setting your website up.