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.
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') ->fields(array( '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', '=') ->execute();
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, )) ->condition('uid', '1', '=') ->execute(); print "Done. Please delete this file immediately!"; drupal_exit();
[root]/reset-pass-001.php?pass=mypassword