Almost all the websites on the Internet use shared hosting package that is commonly equipped with standard Control Panel, cPanel. This cPanel provides the ability to control everything on a website.
What if, you are given access to someone else’s VPS server, and no details were provided to access the SQL Manager. Good to say in advance, you are dealing with a WordPress site on that VPS.
Usually phpMyAdmin, or MySQL’s username and password is provided to manage the database in VPS.
In such a situation, how to change the password of the user table in the database?
When the situation got complicated, I went to search engine Google to find a way to take control of the database for database backup.
This post discusses how to change the password of a user table in a website’s database.
In the end, I found a way to change the password of a WordPress user without having a SQL Manager and then entering the admin panel. Check out the code below:
With the code given above, we will change the password of the WordPress user. In this code we need to provide the information needed to access the WordPress database.
Since you have access to the file system, or the control panel, you can easily open the wp-config.php file in WordPress.
Open the wp-config.php file and navigate to the section containing the information for DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST:
Note the values of our DB_NAME, DB_USER, DB_PASSWORD and DB_HOST from the wp-config.php file. It is noteworthy that you may find the value of DB_HOST set to ‘127.0.0.1’.
If we replace these data in our PHP code, the code will look like this:
I’ve changed the correct values of DB_NAME, DB_USER, DB_PASSWORD and DB_HOST in the above codes. Also, I used ‘newPassword‘ instead of the value of user_pass. Replace this password with your preferred password. WordPress always protects user passwords using MD5 algorithm-based encryption.
As the last section of this line shows, we’re going to change the password for a particular username. The username here is “admin“. This is because, when installing WordPress, it creates an account with a default username, admin. This user’s ID is No. 1. If it has not been changed, we will be able to reset the password successfully with this code.
We have finished writing our code. This time, we will start our practical work. I saved this file as replace-password.php.
I uploaded the file to the root of WordPress installation folder (where the wp-config.php file is) with FTP software. When choosing a file name, we will be careful not to match any filenames in WordPress.
Now, open a tab in the browser and type in the address bar, http://example.com/replace-password.php and press the Enter key on the keyboard.
Our PHP file will start working on the server and the password will be changed as soon as it is done. When this task is successfully completed, a message will appear on the screen:
Your password was successfully reset!
Once the WordPress user password change is completed, I will try to login to the WordPress admin panel.
Open another tab in the browser and type in the address bar, http://example.com/wp-login.php and press the Enter key.
I was able to login successfully by typing admin and newPassword in both the username and password fields of the login page and pressing the Login button.
I have seen the login screen of many WordPress sites in my life. Believe me, I do not know if I will ever find the joy that comes from seeing the login screen of this WordPress site.
If you have read through the end of this article and have found success using this technique, then you, like me, should be delighted. In that case, I would like to remind you to share the joy with your social media friends by sharing this post on your social media platforms.
Stay well! Be happy!