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.
<?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!');
}
21 comments
Reply