Black Friday SALE 50% OFF on the entire line of Qi products Discount code: BLACKFRIDAY2023 Black Friday SALE 50% OFF on the entire line of Qi products Discount code: BLACKFRIDAY2023 Black Friday SALE 50% OFF on the entire line of Qi products Discount code: BLACKFRIDAY2023
Black Friday SALE 50% OFF on the entire line of Qi products Discount code: BLACKFRIDAY2023 Black Friday SALE 50% OFF on the entire line of Qi products Discount code: BLACKFRIDAY2023 Black Friday SALE 50% OFF on the entire line of Qi products Discount code: BLACKFRIDAY2023

How to Reset WordPress Admin Password on Localhost

How to Reset WordPress Admin Password on Localhost

The term localhost indicates a local server, usually set up on your computer. WordPress website creators often opt for installing WordPress in a localhost environment as it offers various benefits. Those benefits include safely testing new plugins and themes, making sure the latest updates and newly created code won’t cause errors, learning about WordPress, and many more. Experienced WordPress users can even create a website in a localhost environment and then migrate it to a live server. To install WordPress on localhost, you can use the XAMPP, MAMP, or WAMP applications.

However, while working in the localhost, users sometimes forget their admin password which makes them unable to access the WordPress dashboard. Forgetting or losing a password can happen to anyone; and it happens often with localhost if you visit your website there infrequently. However, the trouble arises when the usual way of resetting an admin password—password reset email—isn’t applicable. Precisely this is the case with the localhost. And that means users need to find an alternative way to reset their WordPress admin password. Luckily, we made a comprehensive guide explaining how to reset your WordPress admin password on localhost.

Qode Themes: Top Picks
Bridge New Banner

Creative Multi-Purpose WordPress Theme

Stockholm WordPress Theme

A Genuinely Multi-Concept Theme

Startit WordPress Theme

Fresh Startup Business Theme

How to reset a WordPress admin password on localhost

In this section, we will show you three different methods of resetting the WordPress admin password. Even though this article is intended for changing WordPress passwords while in the localhost, the methods described below can be applied to live WordPress websites as well.

If you are trying to reset the password for a live website, you should first try using the Lost your password? link from the login screen. This will take you through resetting the password via email method. If that doesn’t work, you can try one of the approaches described below. And, if you don’t feel comfortable implementing these methods, try finding professional help to do it for you. With that being said, let us see the three ways you can use to reset your WordPress admin password on localhost.

How to reset a WordPress password from phpMyAdmin

PhpMyAdmin is a popular, free, and open-source database administration tool for MySQL and MariaDB. All data belonging to a WordPress website, including passwords, is stored in appropriate tables within a given MySQL database. This means the fastest way of resetting the password is by directly changing its value in the database. We will show you two ways of doing so below.

  • Manually changing the password

To manually change your WordPress admin password, insert http://localhost/phpmyadmin/ into your browser’s address bar, which will open the phpMyAdmin login screen. Then, log in to phpMyAdmin by entering your username and password and pressing the Go button.

phpMy Admin

After that, find the database that your locally hosted website uses in the list of existing databases. Then click on it to see a list of available tables within. Locate the wp_users table and click on it, as well.

phpMy Admin

If you aren’t sure what your database name is or even what the credentials for logging into phpMyAdmin are, don’t worry. You can find them by accessing the wp-config.php file. The wp-config.php file is located in your root WordPress directory. Find the file and open it using any text editor.

Within the file, find the following line, which should be near the top of the file:

define(‘DB_NAME’, ‘your_database_name’);

In practice, the your_database_name part will be replaced with an actual database name. In our example, visible on the screenshot below, the name of the database is test.

After that, look for the define( ‘DB_USER’, ‘your_username’ ); and define( ‘DB_PASSWORD’, ‘your_password’ ); lines of code to figure out the username and password.

WP Config Code

After you find the necessary information from the wp-config.php file, proceed as described above. By clicking on the wp_users table to open it, you will see a list of all current users and their relevant data in the central section of the screen. Look within the user_login column to locate the exact user whose password you wish to change. Then, press the Edit button that is located within the same row as that user.

phpMy Admin 3

If you weren’t able to find the wp_users table, it is most likely that the default WordPress database prefix was changed for security purposes. Instead of looking for wp_users, look for prefix_users (with the prefix part being replaced with an actual prefix). To give you a dummy example, the table might be called qode_users.

After you click on the Edit button, locate the row containing the user_pass column label. Within that row, choose MD5 as the function name and replace the current label found in the Value column with your new password. Afterward, press the Go button below.

phpMy Admin

The processing time should be brief, so wait until you see a success message, stating that the password for the given user was changed.

phpMy Admin 5
  • Running an SQL query

You can execute the same procedure as an SQL query. This method is more suitable for advanced WordPress users who are familiar with writing and executing queries. The benefit of this approach is that it is far quicker for resetting your password.

From within phpMyAdmin, start by clicking on the database of your locally hosted website (in our case, the database is called test). Then click on the SQL tab, located near the top of the central section of your screen.

phpMy Admin

Then, insert the following query in the textarea at the top:

UPDATE `wp_users` SET `user_pass` = MD5( 'new-password' ) WHERE `wp_users`.`user_login` = 'username';
phpMy Admin

Make sure to insert an actual password instead of the new-password label, as well as your correct username instead of the username label. Also, if you have changed the default prefix of your database, replace the wp_ part of the wp_users label with the appropriate prefix.

We advise conducting a dry run of the query first by pressing the Simulate query button. That way, you will be able to see if the query is written properly or not. If you find a syntax error in the query, make sure to double-check the code and fix the error before pressing the Go button.

After a fraction of a second, you should see a success message, stating that your query was run and it successfully affected 1 row. This means it changed the password for one user exactly.

phpMy Admin

How to reset a WordPress password by editing the functions.php file

You can also change the password of your main administrator user by inserting a small code snippet into the functions.php of the currently active theme.

To do so, open the root WordPress directory of your locally hosted website and navigate to the /wp-content/themes/ folder. Open the folder of the theme you are currently using, locate the functions.php file within, and open it using any text editor. Insert the following code at the end of the file:

wp_set_password( 'new_password', 1 );

Make sure you replace the new_password part with an actual password.

Functions Code

Then, save the changes you made to the file and try to log in to your admin dashboard using the main administrator username and the new password you just created.

Login WP

After you log in, open the same functions.php file once more to erase the password reset code you added.

If your first login attempt wasn’t successful, it’s likely you have something in the cache causing you trouble or you haven’t removed the password reset code you added. In that case, make sure to remove the code from the functions.php file and clear your cache. You can even wait a bit before trying to log in again.

We’re going to briefly explain the code and why leaving it within the functions.php file is harmful.

The wp_set_password() function lives up to its name—it resets the password for a given user. This function accepts two parameters. The first is the new password and the second is the ID of the WordPress user. Therefore, by inserting wp_set_password( ‘new_password’, 1 ); you will be changing the current password of the user whose ID is 1 (which is the main administrator user) to new_password.

However, as the function page itself lists, this line of code is meant to be used only once since it could be harmful otherwise. As this code resets the password on every page load, it can cause an endless loop of password resets if left in the functions.php file. This is why you must remove it after changing the password, as mentioned in both possible outcomes above.

Final Thoughts

Having a localhost WordPress website can come in handy for learning or testing purposes. But, in the age of information overload, we tend to forget a lot of stuff. Unfortunately, can include our WordPress admin password, which leaves us unable to log in to our dashboard. To successfully overcome this problem, just closely follow the steps for any of the methods we outlined in this article. If you do so, you can reset the admin password for your localhost WordPress site quite painlessly. And, to avoid such issues from happening in the future, we suggest safely storing your WordPress credentials and keeping them at hand.

Post your comment