Reset Wordpress User Password Easily

Page content

How to Easily Reset Password for a Wordpress User Account

Losing passwords can be frustrating. However, in most cases you can reset the password easily. If you lost your wordpress password, you can reset it from the login.php page. You will receive an email to reset the password. However if your Wordpress email service is not set properly or if for any other reason the mail does not reach you, you might need to try other methods to reset your password. A second method is through the phpmyadmin, where you can change the password using phpmyadmin and by modifying the password inside the database.

However, in this post, we are going to talk about a third method for resetting your Wordpress password. In many cases, you might be required to change your Wordpress password. While it is a good practice to change it often, you must always use strong passwords in Wordpress since weak passwords can get easily hacked. To prevent it you must use strong passwords or you can use a password generation service to automatically generate a very strong password for you.

In this post, we are going to talk about a password reset method for Wordpress that can be used to easily set any user’s password in case of a password loss or account getting hacked. If your website has been hacked, your first step must be to change the password and replace all the passwords with strong new passwords.

Using the WP-CLI to reset the Wordpress password for any user account allows you to easily set a system generated and very strong password. Using the WP-CLi is easy and apart from running a simple command, you do not have to do anything to reset an account’s password in Wordpress whether it is the admin account or subscriber or any other account. If you use the WP CLI method to reset Wordpress password, you can also skip the mail sending part like you do when you reset a user’s password from the wp-dashboard. It is up to you and you can choose to skip or not.

If you have used WP-CLi to accomplish Wordpress tasks, you might be familiar with this method. If not, you do not need any other skill but the ability to run terminal commands and you can become an official WP-CLI user. You will need to install the WP-CLI on your server so that you can run the CLI commands.

Install WP CLI

SSH to your server and then install the WP-CLi using the following command:

curl -O https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar

Check if the CLI works:

php wp-cli.phar --info

Make the file executable and move it somewhere in your PATH so that you can run the commands by typing only wp:

chmod +x wp-cli.phar
sudo mv wp-cli.phar /usr/local/bin/wp

Following that check that the CLI has been successfully installed. Type:

wp –info

You will get an output like the following confirming that WP CLI has been successfully installed:

$ wp --info
OS:     Linux 6.5.0-1018-aws #18~22.04.1-Ubuntu SMP Fri Apr  5 17:44:33 UTC 2024 x86_64
Shell:  /bin/bash
PHP binary:     /usr/bin/php8.1
PHP version:    8.1.2-1ubuntu2.15
php.ini used:   /etc/php/8.1/cli/php.ini
MySQL binary:   /usr/bin/mysql
MySQL version:  mysql  Ver 15.1 Distrib 10.6.16-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper
SQL modes:
WP-CLI root dir:        phar://wp-cli.phar/vendor/wp-cli/wp-cli
WP-CLI vendor dir:      phar://wp-cli.phar/vendor
WP_CLI phar path:       /home/ubuntu
WP-CLI packages dir:
WP-CLI cache dir:       /home/ubuntu/.wp-cli/cache
WP-CLI global config:
WP-CLI project config:
WP-CLI version: 2.10.0

Reset Wordpress Password with WP-CLI

If you remember the username for the account that you are trying to reset the password for, then fine. Otherwise, you will need to first find out the right account and username so that you can reset its password. Don’t worry your task is easy even if you have set a complex username and completely forgotten it. You can still find out all the usernames and their emails on the website using the WP CLI

List Users with WP-CLI

You can draw a list of all the users including their roles and email ids as well as other data like id with the help of a simple WP-CLI command:

You will receive an output like the following:

wp user list
+----+-------------+-----------------+-----------------------+---------------------+---------------+
| ID | user_login  | display_name    | user_email            | user_registered     | roles         |
+----+-------------+-----------------+-----------------------+---------------------+---------------+
| 1  | Wpadmin | John        | Johnabs@gmail.com | 2023-07-02 13:49:05 | administrator |
| 2  | D4danny |Danny | dannyd4@gmail.com | 2023-07-02 14:00:35 | subscriber    |
+----+-------------+-----------------+-----------------------+---------------------+---------------+

The output will include the user id and the first user id must be the administrator. The output also includes the roles of the users, their emails and the day they were registered as well as the login user name and the display name.

So, now we have the user names under user_login. You can find the right login user name and email for the user whose password is to be reset. You are ready with all the necessary information to reset the password for any user.

Reset Password for a user

Resetting the password will be just as easy as finding the user name by drawing a list of users with WP CLI. We will run the wp user reset-password command to reset password for a user. The format of the command is like ‘wp user reset-password username’. However, we can skip the email part where you send an email to the concerned user. So, we will run the command to reset the password and output the password so we can note and save it for use.

Please remember that you must run the WP-CLI commands from the root folder for your website.

$ wp user reset-password Wpadmin --skip-email --porcelain

There will be no other output but only the new password on the screen. You can copy the password. You already have the user name. So, just login with the user name and the new password.

This is how you can easily reset a Wordpress user account’s password using the WP-CLI. If you want to reset the password only for the admin account, you can run the following command:

wp user reset-password $(wp user list --format=ids --role=administrator)

If you want to reset the user password for all the accounts on the website:

wp user reset-password $(wp user list --format=ids)

If you want to reset the user password for a user without skipping email like we did initially:

wp user reset-password user_login