How To Reset Drupal admin password in drupal 7 ?

   comments
Share

There are many ways to reset the admin password in Drupal 7. In this blog, we are exploring possible ways of changing Drupal admin password.

1. Reset password with direct URL

In all Drupal site, page http://example.com/user/password has a simple form that takes username or email address of user and send a one-time auto login link on user e-mail address bounded to that user's account and instructions to set new password.

user_password

2. Using Drush command

The Faster way to Reset password using drush command but you need command line access to server

drush upwd admin --password=yourpassword

3. By Updating user table

Every piece of content in Drupal goes in and out from SQL database. There is no need of mail server or email account associated to admin user when we use this method but you Need access to MySQL server

Go to drupal root directory and run command php scripts/password-hash.sh 'mynewpassword' from command prompt to get encrypted password.

The below SQL query would set the username and password of super admin user (uid 1) to admin and drupal respectively.

UPDATE users SET name='admin', pass='$S$Drl0vgZ9yuU9uc4JyaTMHxMPriC7q/PsOUOx52fCrVQSTpI/Tu4x' WHERE uid = 1;

4. With a PHP file

Create a file with a random name (change_pw.php)

Add below contents into that file, and save the file.

<?php require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); require('includes/password.inc'); echo user_hash_password('newpassword'); die(); menu_execute_active_handler(); ?>

Upload this folder in drupal root(i.e., where index.php exist).

Now, navigate this URL http://example.com/change_pw.php in your browser.

This will generate a long password hash for you to enter into your Drupal database. Make note (copy) this password for the next step.

You'll need to access your Drupal database for this step. Click on the users table, and under the uid column, locate the value 1 (corresponds to user 1). Do an inline edit and copy your generated hash into the corresponding pass field. Once you hit go/save you should be able to log into your Drupal website with the admin user (user 1) using the 'newpassword' you specified above.

5. By template file

Put below code in page.tpl.php file and navigate your site pages.

<?php global $user; $user = user_load(1); print '<pre>'; print_r($user); print '</pre>'; ?>

You will found the user array details including name and password. You can now navigate http://example.com/user and login via this user and password.

6. Create a secondary admin

A good practice to maintained the site by more than one administrators. The Drupal 7 user module have a special role 'administrator'. Create another user with a permission 'administrators' as best security practice which helps to recover when one admin have lost their password.

Add new comment