Skip to content

Instantly share code, notes, and snippets.

@jonasbjork
Created February 10, 2010 17:09
Show Gist options
  • Save jonasbjork/300572 to your computer and use it in GitHub Desktop.
Save jonasbjork/300572 to your computer and use it in GitHub Desktop.
Resets admin pass on WP-site
<?php
/*
* Reset the admin password in a Wordpress site. Run this script from CLI!
*/
if($argc == 1) { die("[Error] You must specify the domainname!\nSyntax: ./$argv[0] <domainname>\n\n"); }
$_SERVER['HTTP_HOST'] = $argv[1];
printf("Trying to reset your administrative password, if successful you should get a [OK] back.\n\n");
define( 'WPPATH', dirname(__FILE__).'/' );
require( WPPATH.'wp-load.php' );
$uname = $wpdb->get_var($wpdb->prepare("SELECT user_login FROM $wpdb->users WHERE id='1'"));
if($uname) {
$wpdb->update( $wpdb->users, array('user_pass' => md5('admin') ), array('id' => 1));
printf("[OK] Updated the first user ($uname) with password 'admin'\n");
} else {
die("[Error] Could not find user with uid 1 in table: ".$wpdb->users."\n");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment