How to reset the WordPress password through FTP

Last updated on October 18th, 2014 by Robert Abela. Filed under WordPress Security Tutorials & Tips

If you lost your WordPress administrator password, or you cannot login to the WordPress dashboard and you do not have access to the WordPress MySQL database, or the password reset functionality is not working, it is still possible to change your password through FTP. In this ten step easy to follow guide we will explain how to change the WordPress administrator password using FTP to be able to access the WordPress dashboard again. If you have access to the phpMyAdmin interface, you can read our WordPress tutorial How to reset a WordPress password using phpMyAdmin in 3 easy steps.

Procedure to reset password WordPress password using FTP

  1. Using an FTP client connect to your WordPress website.
  2. Navigate to the directory of the WordPress theme which is currently enabled on your blog or website. WordPress themes can be found in \wp-config\themes\ directory.
  3. Download the file functions.php of your WordPress theme.
  4. Add the below line of code after the first <?php line. The number 1 at the end of the line of code is the user ID of the WordPress user you would like to reset the password for. If you are using the default administrator account you created when installing WordPress, the user ID is always 1.
wp_set_password('password',1);
  1. Save the changes and upload back the files function.php.
  2. Once uploaded, navigate to your WordPress dashboard login page, typically http://www.yourwebsite.com/wp-admin.
  3. Login to WordPress using the default administrator account name (typically admin) using the password password.
  4. Once you submit the credentials (try to login) the login page will simply reload without redirecting you to the WordPress dashboard. This means you  have just reset the WordPress administrator password to password. Do not try to login again for now. Each time you try to login, you will reset the WordPress administrator account password.
  5. Before trying to login again, using the FTP client download the modified functions.php file from the themes directory.
  6. Remove the line you have added before, save the changes and upload back the file.

Now you can login  to the WordPress dashboard with your administrator account using the password password.

WP White Security.com Security Tip: Once you manage to login, change the WordPress administrator password to a more secure password. A secure password should consist of at least 8 characters and should not be a dictionary word.

WordPress Hosting, Firewall and Backup

This Website is:

24 comments

soifran 12/09/2012

this indeed saved my beacon. thanks a lot. really.

Serena 07/11/2012

I can’t seem to get it to work. The username I have has Admin privileges but the password ‘password’ won’t login.

What if I am not using the default Admin how do I figure out what the User ID number should be?

Thanks

Serena 07/11/2012

Oh I see it is in the order of users added i.e. 1, 2, 3 etc
Thanks

John Bonello 07/11/2012

Hi Serena,

So did you sort out your problem then? Your answer is correct. Users ID are sequential in WordPress so if your user was the second one created, than the user ID is 2.

Let me know if you need further assistance. You can always get in touch with us via our Contact Form.

Wendy 23/11/2012

Thanks. Saved my booty!

Kaleem 24/11/2012

I tried this but it is not working…The following error occurs when i open http://www.domain.com/wp-admin

Fatal error: Call to undefined function phpwp_set_password() in …./functions.php

John Bonello 25/11/2012

Hi Kaleem,

The line “wp_set_password(‘password’,1);” that needs to be added in functions.php should be added below the first line “help@wpwhitesecurity.com.

SH 09/12/2012

Thank you. Much easier to understand than wordpress own support page. Helped me heaps, cheers.

Jerry 26/03/2013

Didn’t work. Nothing happens. Maybe I’m using an old version of WordPress and this code doesn’t work? Any thoughts on how to change the default email so it sends the reset password to a live account?

Robert Abela 26/03/2013

Hi Jerry,

It should work on almost all versions (as long as you don’t have version 1 🙂 ). When it works it does not report a success or a failure, you just update the file, insert the password, change the file and login. If you have problems, maybe we can try something else. Do you have access to the WordPress database? If yes you can reset the password from there. Drop me an email on robert@wpwhitesecurity.com so we guide you through the rest.

Jerry 28/03/2013

Hi Robert,

OK. It did actually work. I just neglected to remove the code from the functions.php file after I was done. It actually resets the password… I get it!

Need to update my theme and portfolio to feature my video production and motion graphics work. Any suggestions on a particular theme?

Thank you!
Jerry

Robert Abela 29/03/2013

Perfect! Well I cannot recommend any themes, i.e. there are many good themes out there. Though I would recommend you this reading before you start searching; Getting Started with WordPress Themes.

John Young 29/10/2013

Thank you for this it was a great help

Matt 25/02/2014

What if the username is not Admin, this does not seem to be working for me? I try and when I go to login Im getting the invalid username error. I have also tried user id 1, 2, 3, 4…any other ideas or any way to reset the username for id1?

Robert Abela 26/02/2014

Hi Matt,

If the default Admin account was renamed then you mus specify the new account name. In your case it seems you renamed the username and cannot find the right one. Do you have access to the database? Contact us on support@wpwhitesecurity.com and we will help you solve your issue.

Nigel Sanders 17/07/2014

Thanks! Wow! Helped me get out of a jam. Thank you again.

Chris 14/08/2014

This SAVED me!! Thanks a billion!!!

WP 20/08/2014

Wow, didn’t know trick with wp_set_password. When I lost my password and there was no phpmyadmin, I was forced ;/ to write little script:
http://www.digitalette.com/wordpress/reset-wordpress-admin-password/
Also, maybe you know whether wp_set_password supported on all WordPress versions? If so then it’s best thing I’ve learnt about WP this year 🙂

thanks

Robert Abela 24/08/2014

Hi WP,

Thanks for sharing your script, very simple but definitely very handy! wp_set_passwords have been supported for very long, though not sure since when. But it is supported in all latest versions 🙂

Dianne 02/10/2015

I get a Fatal error no matter what I try…

Fatal error: Call to undefined function wp_set_password() in /../wp-includes/functions.php on line 2

The Functions.php file looks like this

<?php
wp_set_password(password,1);

/**
* Main WordPress API
*
* @package WordPress
*/

Dianne 02/10/2015

<?php
Sorry it is

wp_set_password('password',1);

/**
* Main WordPress API
*
* @package WordPress
*/

I tried with single, double and no quotes…

Robert Abela 08/10/2015

Hi Dianne,

If it did not work for you drop us an email on support@wpwhitesecurity.com and we will help you sort it out.

Edwin Masripan 20/07/2019

Just to update this.

This is how I do it.
1. Copy to functions.php, remember to change “Hello World”. Change user ID accordingly.

2. Go to default URL.

3. Go back to function and delete what you’ve pasted.

4. Go to wp-admin, use the new password.

Robert Abela 30/07/2019

Thanks for the feedback Edwin. Yes, that is another way of doing it. In both cases you are using SFTP so it is really up to the user which method he / she prefers.

Leave a Reply

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