The term localhost usually refers to a local server installed on your computer. WordPress website builders prefer to install WordPress in a localhost environment as it offers several benefits. These benefits include safely testing new plugins and themes, making sure the latest updates and newly created code won’t cause bugs, learning about WordPress, and more. Experienced WordPress users can even create a website in a localhost environment and then migrate it to a live server. You can use XAMPP, MAMP or WAMP applications to install WordPress on localhost.
However, when running on localhost, users sometimes forget their admin password, making them inaccessible to the WordPress dashboard. Forgetting or losing a password can happen to anyone; and if you rarely visit your website, this usually happens with localhost. However, the problem occurs when the password reset email, which is the usual way to reset the administrator password, is not valid. This is exactly the case with localhost. This means that users must find an alternative way to reset their WordPress admin password. Fortunately, we have prepared a comprehensive guide explaining how to reset your WordPress admin password on localhost.
How to reset a WordPress admin password on localhost
In this section, we will show you three different methods to reset WordPress admin password. While this article is designed to change WordPress passwords while on localhost, the methods described below can also be applied to live WordPress websites.
If you are trying to reset the password of a live website, first Did you forget your password? connection from the login screen. This will take you to reset the password via email. If that doesn’t work, you can try one of the approaches described below. And if you don’t feel comfortable using these methods, try to find professional help to do it for you. That said, let’s see three ways you can use to reset your WordPress admin password on localhost.
How to reset a WordPress password from phpMyAdmin
phpMyAdmin It is a popular, free and open source database management tool for MySQL and MariaDB. All data belonging to a WordPress website, including passwords, are stored in appropriate tables in a specific MySQL database. This means that the fastest way to reset the password is to directly change its value in the database. Below we’ll show you two ways to do this.
To manually change your WordPress admin password, sting http://localhost/phpmyadmin/ into your browser’s address bar.It will open the phpMyAdmin login screen. At that time, Login to phpMyAdmin by entering your username and password and print To go button.
Later on, find the database your locally hosted website is using in the list of available databases. back then click on it to see a list of available tables in it. find wp_users table and click on it, additionally.
Don’t worry if you’re not sure what your database name is or even what credentials are required to log into phpMyAdmin. You can find them by accessing the wp-config.php file. The wp-config.php file is located in your root WordPress directory. find file and open it using any text editor.
In the file, find the following line, which should be near the top of the file:
define(‘DB_NAME’, ‘your_database_name’);
In practice, yourdatabase_name part will be replaced with an actual database name. In our example shown in the screenshot below, the name of the database Scale.
Later on, To search define(‘DB_USER’, ‘your username’); and define(‘DB_PASSWORD’, ‘your password’); lines of code to find the username and password.
After finding the necessary information from the wp-config.php file, proceed as described above. by clicking on wp_users To open the table, you will see a list of all current users and their related data in the middle part of the screen. Look in the user_login column to find the exact user whose password you want to change.. At that time, Press To organise button located on the same line as this user.
If you couldn’t find wp_users table, it is likely that the default WordPress database prefix has been changed for security purposes. instead of calling wp_usersto search prefix_users (with prefix fragment is replaced with an actual prefix). To give you a mock example, the table could be named like this: qode_users.
after clicking on To organise button, find the line containing User switch column label. In that row, select MD5 as function name and replace the existing tag in Value column with your new password. After that, Press To go button under.
Processing time should be short, so wait until you see a success message stating that the given user’s password has been changed.
You can follow the same procedure with 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 resetting your password is much faster.
From within phpMyAdmin, start with: clicking on your locally hosted website database (in our case, the database is called Scale). back then Click the SQL tabis located near the top of the middle of your screen.
At that time, add below query to textarea at the top:
UPDATE `wp_users` SET `user_pass` = MD5( 'new-password' ) WHERE `wp_users`.`user_login` = 'username';
Make sure you enter a real password instead. new password instead of your correct username as well as the tag User name ticket. Also, if you changed the default prefix of your database, wp_ a part of wp_users Label with the appropriate prefix.
First, we recommend that you dry-run the query by pressing the button below. simulate query button. This way you will be able to see if the query was written correctly. If you find a syntax error in the query, be sure to double-check the code and correct the error before pressing the button. To go button.
In less than a second you should see a success message stating that your query has been run and has successfully affected 1 row. This means that a user has exactly changed their password.
How to reset a WordPress password by editing the functions.php file
You can also change the password of your main admin user by adding a small code snippet to the currently active theme’s function.php file.
By doing so, open root WordPress directory of your locally hosted website and Go to /wp-content/themes/ folder. Open the folder of the theme you are using, find the function.php file in and open it using any text editor. Enter the code below at the end of the file:
wp_set_password( 'new_password', 1 );
make sure you change it. new password partition with a real password.
At that time, save your changes to the file and try logging into your admin panel using the main admin username and the new password you just created.
To delete the password reset code you added after logging in, open the same function.php file once again.
If your first login attempt was not successful, there may be something with the cache that is causing you problems, or you may not have removed the password reset code you added. In this case, be sure to remove the code in the function.php file and clear your cache. You can even wait a bit before trying to log in again.
We will briefly explain the code and why it is harmful to leave it in the function.php file.
This wp_set_password() the function lives up to its name—resets the password for a specific user. This function accepts two parameters. The first is the new password, and the second is the WordPress user’s ID. Therefore, by intervening wp_set_password( ‘new_password’, 1 ); You will change the current password of the user with id 1 (who is the main admin user). new password.
However, as the function page itself lists, this line of code should only be used once as it could be harmful otherwise.. Since this code resets the password on every page load, if left in the function.php file it could result in an endless password reset loop. So, as mentioned in both possible outcomes above, you should remove it after changing the password.
final thoughts
Having a localhost WordPress website can come in handy for learning or testing purposes. However, in the age of excessive information, we tend to forget many things. Unfortunately, it may contain our WordPress admin password which caused us to be unable to log in to our dashboard. To successfully overcome this issue, follow closely the steps of any of the methods we have outlined in this article. If you do, you can reset your localhost WordPress site’s admin password pretty effortlessly. And to prevent such problems from happening in the future, we recommend that you securely store and keep your WordPress credentials handy.
Support our work ❤️
If you enjoyed this article, consider leaving a tip to help us keep publishing great content.


























