WordPress password reset

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.

<?php
$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 = '127.0.0.1'; # 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,
        )) ;
        var_dump(get_userdata($user));
        die('disable me!');
}

Published on Oct. 18, 2012 at 3:03 p.m. by Nicolas and tagged WordPress, password. You can follow the discussion with the comment feed for this post. Feeling generous? Donate!

0 comments

Start a new thread

Cancel reply
Markdown. Syntax highlighting with <code lang="php"><?php echo "Hello, world!"; ?></code> etc.