Tuesday, September 8, 2015

Resetting the admin password of Drupal 7

Frequently we come across Drupal sites where admin  password is not known to the owner of the site. You can retrieve the password by changing the email address of user 1 to your email address and then use the forgot password option to reset your password. But if you don't want to change the user 1 email address but instead just want to change the password of user 1 there is an easier alternative

Use below PHP Code in index.php of drupa with URL paramas as  ?pass=PASSWORD and run. After that roll back to old index.php
 
It Will  set your admin password to PASSWORD

define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once DRUPAL_ROOT . '/includes/password.inc';
if (isset($_GET['pass']) && !empty($_GET['pass'])) {
  $newhash user_hash_password($_GET['pass']);
}
else {
  die('Retry with ?pass=PASSWORD set in the URL');
}
$updatepass = db_update('users') 
  ->fields(array(
    'pass' => $newhash,//    'name' => 'admin',
//    'mail' => 'yourmail@example.com'
  ))
  ->condition('uid', '1', '=')
  ->execute();
print "Done. Please delete this file immediately!";drupal_exit();?>

No comments:

Post a Comment