Drupal reset admin password 7

Just think what would happen, if you forget the drupal admin password? This situation can can happen anytime, so we must know how to reset the admin password.

How to reset drupal 7 admin password

This is very common situation when we forget admin password for drupal login

Step 1:
Update the new password using mySql query

Note: Drupal use one way hashing techniques for password encryption, So while updating the password you need to use MD5 built-in function in mysql

    UPDATE drupaldb.users SET pass = MD5('dpass123') WHERE uid = 1;

Step 2:
After resetting the password, clear the data from flood table, this flood table records username and ip which has failed login attempts

// Check details
 SELECT * FROM drupaldb.flood f; 

Delete or truncate TABLE drupaldb.flood

Step 3:
Reset password from php code, write the following code and execute on server

$updatepass = db_update('users')
'pass' => $newhash,
// Uncomment the following lines to reset the administrative username and/or email address, if necessary.
// ‘name’ => 'admin',
// 'mail' => 'yourmail@example.com'
->condition('uid', '1', '=')
  • Create a php file name with some random name [Note: you must delete this file onece resetting is done.], lets call the file name "reset-pass-001.php"
  • Paste the following code in that file
    define('DRUPAL_ROOT', getcwd());
    require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    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, ))
    ->condition('uid', '1', '=')
    print "Done. Please delete this file immediately!";
  • Upload the file to the root of the Drupal installation directory (i.e., where update.php, index.php, robots.txt and other files and directories exist).
  • Execute the script, by requesting the file in a web browser using the following URL pattern: [root]/reset-pass-001.php?pass=mypassword
Drupal Resource Links
Reset drupal 7 admin password

Learn Drupal Development