11 ways to recover your forgotten admin password WordPress

If for some reason you do not know the correct password in the admin panel of your WordPress site – it does not matter. There are many ways to reset it and install a new one.

1. Password recovery by email

Go to the login page in the admin panel, it is usually located on the link like https://site.com/wp-admin , and click on “Forgot your password?”

wp login page

After that, write the email to which your account is linked. An email will be sent to the specified address with a link to set a new password. Of course, this method is only suitable if you used a real email address when setting up your administrator account.

2. Set a new password in phpMyAdmin

Open the hosting / server control panel and find the phpMyAdmin item there . It is usually located in the Database, MySQL or similar section . In the cPanel panel, the transition button looks like this:

phpmyadmin cpanel

Here is the link in the ISPmanager 5 panel :

phpmyadmin ispmanager

And in the Centos Web Panel :

cwp phpmyadmin

After logging into phpMyAdmin, it is important to choose the correct database that is connected to the site. If you do not know which database you need, then open the wp-config.php file in your site folder in any convenient way.

Select the desired base and table. The table will be called prefix_user , where instead of prefix_ is the prefix value from the wp-config.php file . The default prefix is wp_ . Select the table and next to the user you need, click Edit .

In the line user_pass in the field Value specify your new password. Be sure to use the complex combination created in the password generator. In the Function field, select MD5 . And click below the Forward button .

phpmyadmin reset password

3. Change Password in Softaculous

This method is suitable if you installed WordPress using Softaculous auto -installer of scripts. To set a new password in the admin panel, go to the site cPanel, section Software .

softaculous cpanel

Next, click Installations and choose to edit the installation you want.

softaculous installations
softaculous edit installation

Scroll down the settings page to the Admin Account item   enter your username and password and save with the button at the bottom of the page.

change admin password softaculous

4. SQL query to the database via phpMyAdmin

You can simply execute a query to the database through the query panel in phpMyAdmin. To do this, you need to know the name of the database and the login of the administrator to whom you want to reset the password.

sql phpmyadmin

In the console you need to insert the following code:

UPDATE wp_users SET user_pass = MD5 ('newpass') WHERE user_login = 'admin'

Instead of the wp_ prefix, it can be different, your login and password are also yours. Do not forget to set the most complex password as possible.

What to do if you have forgotten not only the password, but also your account login? If you remember the administrator email, then your request will be as follows:

UPDATE wp_users SET user_pass = MD5 ( 'newpass' ) WHERE user_email = '[email protected]' ;

Accordingly, substitute your email.

Or do you remember that the account number is exactly the first, that is, you did not designate someone else as the chief administrator — in this case, change the password like this:

UPDATE wp_users SET user_pass = MD5 ('newpass') WHERE ID = 1;

If it happened that all users from the wp_users table were gone, or you accidentally deleted a user, and why that could have happened, then you can create a new admin panel user with administrative rights through queries to the site database.

INSERT INTO `db`.`wp_users` (` ID`, `user_login`,` user_pass`, `user_nicename`,` user_email`, `user_url`,` user_registered`, `user_activation_key`,` user_status`, `display_name`) VALUES ('2', 'newuser', MD5 ('newpass'),' newuser ',' [email protected] ',' ',' 2019-03-25 00:00:00 ',' ',' 0 ',' New User ');
INSERT INTO `db`.`wp_usermeta` (` umeta_id`, `user_id`,` meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_capabilities',' a: 1: {s: 13:" administrator "; s: 1:" 1 ";} ');
INSERT INTO `db`.`wp_usermeta` (` umeta_id`, `user_id`,` meta_key`, `meta_value`) VALUES (NULL, '2', 'wp_user_level', '10');

It is obvious that in these queries it is necessary to replace the user’s data with yours (after the word VALUE in the first query). If you specify a user ID that already exists, you will get an error. User ID must not exist in the table before creation (in the example ID = 2).

5. SQL-query to the database via the console

This method is very similar to using phpMyAdmin and is suitable if your server does not have a control panel and phpMyAdmin, or you prefer to use the console.

So, you need to connect to the server via SSH and open the mysql console :

~ $ mysql -u db_user -p db_name

Username and database specify your own. Next, enter your user password.

To find out the name of the tables in the db_name database , use the command:

mysql> SHOW TABLES IN db_name;

+ --------------------------- +
| Tables_in_my_database |
+ --------------------------- +
| wp_commentmeta |
| wp_comments |
| wp_options |
| wp_postmeta |
| wp_posts |
| wp_term_relationships |
| wp_term_taxonomy |
| wp_termmeta |
| wp_terms |
| wp_usermeta |
| wp_users |
+ --------------------------- +

To get a list of user logins from the corresponding table, use the command:

mysql> SELECT user_login FROM wp_users;

+ ---------------- +
| user_login |
+ ---------------- +
| test |
| user |
| admin |
+ ---------------- +

Next, to reset the password or create an administrator, execute the commands specified in the previous paragraph.

6. Setting a new password in the file wp-login.php

This method requires access to the site files. Open the wp-login.php file in the site folder in any convenient way (via the file manager of the server control panel, via FTP, SSH, etc.) At the end of the file, after all the code, add the line:

wp_set_password ('yournewpassword', 1);

Instead of yournewpassword, specify your new password, instead of 1, you can specify a different admin panel user ID if you need to set a password for a non-first user. Save the file and check the access to the admin panel with a new password. This method is well suited if you are the only administrator or clearly know the ID of the user being restored.

7. Setting a new password in the site theme functions.php file

For this method you need to know the theme included for the site. Open the file /home/user/public_html/wp-content/themes/your-theme/functions.php in any convenient way.

/ home / user / public_html / – the path to the site folder, you may have another 
your-theme – the name of your theme – change it to your

Add the following code at the end of the file (instead of newpass write the new password) and save:

if (isset ($ _ GET ['init_new_pass_set']) && $ login = $ _GET ['init_new_pass_set']) {
add_action ('init', function () {
wp_set_password ('newpass', get_user_by ('login', $ login) -> ID);
wp_die ("The password of the user` $ login` is changed ");

After that, open your website on any page and add at the end of the URL ? Init_new_pass_set = username , where instead of username is your user. For example, you can open the main page like this: http://site.com/index.php?init_new_pass_set=admin

As a result, the admin user password will be changed to newpass . After gaining access to the admin panel, be sure to remove this code from the functions.php file .

8. Authorization without changing the current password in the functions file of the site theme.

If you do not want to change the current user password, but you need to get into the admin panel, you can use the wp_set_auth_cookie () function .

The code below shows how to log in as an administrator without changing his password. Open the file in the following path /home/user/public_html/wp-content/themes/your-theme/functions.phpand add the code at the end:

if (isset ($ _ GET ['login_as_admin'])) {
add_action ('init', function () {
$ users = get_users (['role' => 'administrator']);
wp_set_auth_cookie ($ users [0] -> ID);

Then go to any page of the site and write at the end of the URL ? Login_as_admin , For example, http://site.com/index.php?login_as_admin . After that, you will automatically be logged in as an administrator.

After using this code, it must be removed. Leaving it is not safe!

9. Change user password through WP-CLI

WP-CLI is a script for working with CMS WordPress on the command line. More information about it can be found on the official website , and instructions on how to configure it on the hosting –  in our knowledge base .

The user password can be changed using the wp user update command :

wp user update USERNAME --user_pass = "PASSWORD"

Here replace USERNAME with the required login and PASSWORD with your password.

If you do not remember the login, then you can get a list of users with the wp user list command :

wp user list
+ ---- + --------------- + -------------- + ------------- -------- + --------------------- + --------------- +
| ID | user_login | display_name | user_email | user_registered | roles |
+ ---- + --------------- + -------------- + ------------- -------- + --------------------- + --------------- +
| 4 | admin | Alex | [email protected] | 2018-04-24 21:04:24 | administrator |
| 7 | editor_den | Denis | [email protected] | 2018-06-06 23:30:54 | editor |
| 9 | developer | dev | [email protected] | 2018-08-11 13:27:09 | developer |
| 8 | editor_vlad | vlad | [email protected] | 2018-03-26 00:11:48 | editor |
+ ---- + --------------- + -------------- + ------------- -------- + --------------------- + --------------- +

10. Script to reset the password in the admin panel

This script allows you to:

  • If the user does not exist, create it and immediately grant administrator rights;
  • If the user exists, change his password;
  • Assign a user as an administrator;
  • If WordPress works in Multisite mode, designate the user as the super administrator of the WordPress MU network.

You need to create a file in UTF-8 encoding without a BOM (best of all, use Notepad ++ or similar) with the name change_admin_password.php or with any other name and extension .php and paste the code there:

<? php

/ **
* Create a user or modify an existing one, and grant him admin and super admin rights
* After use, be sure to remove or disable, commenting out the first line add_action
* /
add_action ('init', 'password_update_user');

function password_update_user () {

// Login. Change to your
$ user_login = 'here login';
// Password. Change to your
$ user_pass = 'tupparol';
// user role
$ role = 'administrator';

// If user with login $ user_login exists
if (username_exists ($ user_login)) {

// By login we get an object with user data
$ user = get_user_by ('login', $ user_login);

// Get the user ID
$ ID = $ user_id = $ user -> ID;

// If the set password does not match the above, or the user is not an administrator
if (! wp_check_password ($ user_pass, $ user -> data -> user_pass) ||! in_array ('administrator', $ user -> roles)) {

// Change his password to the above
wp_set_password ($ user_pass, $ user_id);

// Update User Profile
$ userdata = compact ('ID', 'user_login', 'user_pass', 'role');

// Get the user ID
$ user_id = wp_update_user ($ userdata);
} else {

// User does not exist, create it
$ userdata = compact ('user_login', 'user_pass', 'role');
$ user_id = wp_insert_user ($ userdata);

// If the user data could not be updated, write it to the logs
if (is_wp_error ($ user_id)) {

error_log ('Failed to update user data');
error_log ('get_error_message ='. $ user_id -> get_error_message ());
error_log ('get_error_code ='. $ user_id -> get_error_code ());
// If the site is in Multisite mode
elseif (isset ($ user_id) && is_multisite ()) {

// Give the user rights superadmin
require_once ABSPATH. 'wp-admin / includes / ms.php';
grant_super_admin ($ user_id);

You can download the file with the script by the link , unpack the archive and enter the login and password in the required fields. Then you need to upload the file in any convenient way to the / home / user / public_html / wp-content / mu-plugins / folder . If there is no such folder, you need to create it. Of course, instead of the path / home / user / public_html / you may have another.

After installing a new password and gaining access to the admin panel, be sure to delete this file!

11. Script Yoast User Manager

This script is similar to the previous one, but a little easier to use. You need to download the archive , download the unpacked script to the folder of your site ( / home / user / public_html / ) and open its name in the browser, for example http://site.com/emergency.php . Next, select the option to reset the password or create a new administrator and enter the database password. The password for the site database can be found in the wp-config.php file in the root folder of the site in the lines:

/ ** MySQL database password * /
define ('DB_PASSWORD', 'some_password');
yoast user manager
Yoast user manager configuration

In addition to the password, this script can also change the access rights (role) and other user parameters. After use, do not forget to delete the file from the site folder.

These were all the ways to restore access to the WordPress admin panel that we were able to find. Choose the most convenient and easiest for you.

One Reply to “11 ways to recover your forgotten admin password WordPress”

Leave a Reply

Your email address will not be published. Required fields are marked *