WordPress password reset

Update: See also http://kuttler.eu/code/wordpress-emergency-admin/ which is a little easier to use.

Recently I had to update a site but didn't have an admin account or access to the SQL database. So I wrote this short script to reset a forgotten password.

To use it, edit it and fill in the proper values. Then upload it to the wp-content/mu-plugins/ directory, create the directory if necessary.

The code will run automatically, there's no need to activate it like a plugin, but you have to delete the file after using it.

The script may also fail if there is no user with an ID of 1.

$user_id = 1; # Insert your user ID or simply 1 for the first user that was created
$user_pass = 'secret'; # Insert a new password
$ip = ''; # Insert your IP

if ($_SERVER['REMOTE_ADDR'] === $ip) {
        require_once(ABSPATH . WPINC . '/registration.php');
        require_once(ABSPATH . WPINC . '/pluggable.php');
        $user = wp_update_user(array(
                'ID' => $user_id,
                'user_pass' => $user_pass,
        )) ;
        die('disable me!');


  1. avatar
    wrote this comment on
    Hello, The web developer no longer exists and when I try to renew the password to gain access to work on my site,I received a key to click on: "http://[edit]/login/?action=rp&key=c4xyVcPuD9Z4MTWs8llF&login=malcolm," however the following is the reply from the log in page: "Sorry, that key does not appear to be valid." How can I renew the password and gain access to my website and please note that I am by far an expert at computer work. Your soonest reply would be much appreciated Malcolm
  2. avatar
    wrote this comment on
    Is this the built-in reset form? You should probably try again, maybe it's just expired. The script I posted here could also be used, I thought the instructions were enough.. maybe not. I'm also available for hire, please see my contact page.
  3. avatar
    wrote this comment on
    Hi, A few questions: 1) How to I actually get it to run? Will it run automatically by going to my site? 2) I'm not using multiuser, so I presume I put the file in wp-content/plugins/ instead of mu-plugins? 3) Does the file have to have any specific name?
  4. avatar
    wrote this comment on
    1) Yes 2) No 3) No See also http://codex.wordpress.org/Must_Use_Plugins
  5. avatar
    wrote this comment on
    I was editing my wordpress site and login details. I forgot to write down the info before closing the window and I worked for quite a while now have no access because I dont remember the login in username or password. neither do I have access to the email. I urgently need help. Please advise.
  6. avatar
    wrote this comment on
    I wouldn't hit a dead dog in the assignment with their coding or support! I'm locked out too..and DONE with WP!
  7. avatar
    wrote this comment on
    I'M confused. How would I upload anything If I don't have to password to even login I've seen a number of these scripts, but I have not access at all and to ability to get to root directories either. What now?
  8. avatar
    wrote this comment on
    Did you ever get this resolved?
  9. avatar
    wrote this comment on
    FTP, scp, whatever still works.
  10. avatar
    wrote this comment on
    It worked! Thanks for this script!!!!
  11. avatar
    wrote this comment on
    I haven't accessed my WP.org site in a few years. I couldn't remember either my user name or password so I put in my email address to get a password reset but it said it didn't recognize the email address. It's the only email I use? HELP!
  12. avatar
    wrote this comment on
    This code is for the self-hosted wordpress flavor, are you using that? I'm available for hire, see my contact page.
  13. avatar
    wrote this comment on
    Umm, a little more step by step instruction would be appreciated. What values are we supposed to change? The items in red? If so, change them to what? and if you had a video of this that would be best. Remember most of the people looking for this answer are probably not coders. you need to walk thru each step, step by step for us.
  14. avatar
    wrote this comment on
    Hi kiara, you should probably have a look at http://kuttler.eu/code/wordpress-emergency-admin/ instead. That code creates a completely new admin and is a little easier to use.
  15. avatar
    wrote this comment on
    I have the same problem. I was using a 2nd computer and didn't have my password memorized - it wouldn't take the one I thought it was. So I reset it and now none of my regular PWs work! I can't find out how to reset it, I don't use FTP and I can't figure out what you guys are talking about. I think it's ridiculous that WP doesn't have a PW reset option! I have at least 20 pages plus forms that have to be updated regularly! Is there any solution for website dummies? Thanks!
  16. avatar
    wrote this comment on
    You can use wordpress.com if hosting your own wordpress doesn't work for you. You can get your FTP details from your hosting provider.
  17. avatar
    wrote this comment on
    Working on accessing my site - I think I commented on your other post about an error message I'm getting. I figured out the username for the site so I tried this method again but getting a very similar error message. Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING) in /home/xxxx/public_html/wp-content/mu-plugins/user-pw.php on line 14
  18. avatar
    wrote this comment on
    What's on your line 14? Try removing the var_dump maybe.
  19. avatar
    wrote this comment on
    Hello Nicolas, I tried your script on my wordpress but it's not working. Either this one or the other emergency script you gave worked for me. I triple checked the path, the ip adress, the user id and password. Really nothing is happening, just "invalid username" in any case. I'm pretty desperate to built my wordpress from scratch again, so if you have any idea, I would really appreciate some help.
  20. avatar
    wrote this comment on
    That's odd. I don't really know what could be going on. Please paste the entire error.
  21. avatar
    wrote this comment on
    Hi Nicolas, I have tried using the code provided to no avail. Would this override any other problems. What information would be required to replace $_SERVER in the code? I would appreciate any help. Thanks, Deidre


Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.
DjangoPythonBitcoinTuxDebianHTML5 badgeSaltStackUpset confused bugMoneyHackerUpset confused bugX.OrggitFirefoxWindowMakerBashIs it worth the time?i3 window managerWagtailContainerIrssiNginxSilenceUse a maskWorldInternet securityPianoFontGnuPGThunderbirdJenkinshome-assistant-logo