How to Change WordPress Password without any SQL Manager

WebTechRiser.com > WordPress > How to Change WordPress Password without any SQL Manager

Almost all the websites on the Internet use a shared hosting package that is commonly equipped with a 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 are 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 the 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:

<?php
// Connect to mySQL First
$connection = mysql_connect( 'DB_HOST', 'DB_USER', 'DB_PASSWORD' );

// Select Database
mysql_select_db( 'DB_NAME' );
 
// Reset password with SQL UPDATE Query
$SQL = "UPDATE wp_users SET user_pass = MD5( 'newpassword123here') WHERE user_login = 'admin'";

// If everything is OK, your password will be reset
if( mysql_query( $SQL ) ) {
     echo "Your password was succesfully reset!";
}

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.

Also read:  How to add Google Translate to WordPress Site

Open the wp-config.php file and navigate to the section containing the information for DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST:

// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'database_123');
 
/** MySQL database username */
define('DB_USER', 'user_123');
 
/** MySQL database password */
define('DB_PASSWORD', 'password_123');
 
/** MySQL hostname */
define('DB_HOST', 'localhost');

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:

<?php
//Connect to mySQL First
$connection = mysql_connect( 'localhost', 'user_123', 'password_123' );
 
//Select Database
mysql_select_db( 'database_123' );
 
//Reset password with SQL UPDATE Query
$SQL="UPDATE wp_users SET user_pass = MD5('newPassword') WHERE  user_login = 'admin'";
 
//If everything's OK, your password will be reset
if( mysql_query( $SQL ) ) {
	echo "Your password was succesfully reset!";
}

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.

Also read:  How to change the Date and Time format in WordPress?

I uploaded the file to the root of the 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 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 log in 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 log in 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!

Category WordPress

Leave Your Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.