Skip to content
Eduardo Lira

WORDPRESS · BANCO-DE-DADOS

How to Reset Administrator Password in WordPress in Case of Lockout

Learn how to reset the administrator password in WordPress when dashboard access is locked, using SQL queries or manipulating the active theme's functions.php file.

This is a very cool tip for those who manage [Wordpress.org] installations. It is always more difficult when we need to fix an error and do not have administrative access to the tool. In a well-made and secure installation, generally none of the passwords contained in the [wp-config.php] file access the administration. Even the reset by the database has no effect, because there is a key in wp-config.php.

First check if the login lockout did not occur due to a recently installed plugin or theme. In this case it is even simpler, as you just need to disable it for correction.

Below is the most known hack for password change. Only setting MD5 in the password field in this case should not help. But be sure to try this query first for access reset.

UPDATE wp__users SET user_pass = MD5('newpassword')
WHERE user_login = "admin";

You have access to the database to view the content of the table wpusers(my prefix is wp ). The user_login column has the login of users registered in Wordpress. Generally the administrator is one of the first registered users. Thus, the lower the value of the “ID” attribute, the greater the chance of being the site ADM.

If the first method worked, then great! Otherwise, let’s break the Wordpress password in a different way. When accessing the administration of your database probably with [phpMyAdmin], after selecting the database where the application is installed execute the following SQL query:

SELECT option_value FROM `wp__options`
WHERE option_name = "current_theme"

Remembering that you must use your table prefix in the query.

The query above will show us the currently active theme. This information will be important for what we need. Of course, if you already know the active theme in the application you do not need to execute this query.

Knowing that the active theme is “Twenty Eleven” for example, let’s go to the theme directory, in the installation path -> wp-content/themes/twentyeleven. Through the file functions.php we will start the fun.

Every self-respecting Wordpress theme has a file named functions.php. If yours does not have it, just create it in the theme directory. In editing the theme’s functions.php, right at the beginning we will add the code below after opening the php tag.

wp_set_password ('123456', 1);

In older versions, it seems, it was just adding the code above in the theme’s functions.php, refreshing the login page and then you could break the password defining the new 123456 for the user with ID = 1 (Usually the administrator). Maybe it still works for some installations.

In the case of this post, the learning acquired occurred because none of the password reset options indicated by the application documentation had any effect. See more details on this page: [Resetting Password]

Continuing…

By adding wp_set_password we pass the first interesting parameter for us (save and refresh the login page, without trying access yet). Wordpress will check the encryption, so access cannot be performed yet. Now let’s pass the second parameter and validate our new password. Change only from set to hash and it will look like the code below:

wp_hash_password ('123456', 1);

Save the functions.php again and refresh the Wordpress administrative login page. At this moment you will be able to perform access with the new password 123456 and login that has ID = 1.

This tip has always worked for me. Probably there is a way to pass wp_set_password and wp_hash_password at once using logic, but that is for another day. Remembering that the access user and id for the password reset can be acquired in the database administration of your Wordpress installation, in the table yourprefix__users. In my tests the table prefix was wp__. Here is a last query for you to view the user login and the corresponding ID.

SELECT ID, user_login
FROM  `wp__users`
LIMIT 0 , 30

So that’s it folks, for those who will only access momentarily, just take the content of the user_pass field in the database before changing and then resend the column content. Surely, depending on your degree of knowledge, we can improve the post by answering questions and sharing other ideas. Thx!

wordpress.org wp-config.php phpmyadmin Resetting Password

Revisited in November 2026

The trick worked, but, rereading the code, it works for a different reason than the one I wrote:

  • wp_set_password('123456', 1) alone already changes the password of the user with ID 1. Since functions.php runs on every page, it changes it again on every load and kills open sessions.
  • wp_hash_password only computes a hash and returns it; it doesn’t save anything. Swapping set for hash “validated” the password because it made the code stop resetting it on every page.

So the safe procedure is: add the line, load a page once, delete the line and log in. And replace the 123456 password with a strong one right after.

I also wrote that resetting through the database didn’t work because of a key in wp-config.php. The keys and salts in that file protect the login cookies, not the password stored in the database. When the UPDATE doesn’t solve it, the cause is somewhere else, such as the wrong table prefix or a security plugin.

Today, if the server has WP-CLI, the shortest route is a single command:

wp user update admin --user_pass="a-strong-password"

A version note: since WordPress 6.8, from April 2025, passwords are stored with bcrypt. The UPDATE with MD5() was designed for the old format; on a current version, prefer WP-CLI or the “Lost your password?” link, and if you try MD5, check that the login actually accepts it.

Who writes this

Eduardo Lira

Software developer in Rio de Janeiro. I started this blog in 2012, in technical support at a hosting company, writing down the fixes for the problems that came up every day. Today I work at Sofis Tecnologia, on critical healthcare systems and SQL Server database migrations.

Found a mistake in this post?

A command that no longer works, a broken link, wrong information: tell me what you saw. The message goes only to the author and is not shown on the site.