How to reset admin password in Drupal 7

How to reset admin password in Drupal 7

Previously for Drupal 6 site, when you forgot or didn't know the admin password, you could easily change it via database by following query:

UPDATE users SET pass = MD5('mynewpassword') WHERE uid = 1; 

However if you tried that in Drupal 7 site you will see it doesn't work! Thats because Drupal 7 stores a salted SHA512 hash instead of MD5 hex hash. To get new password you must use the user_hash_password('mypassword') function (located in includes/, then paste it into the database.

Open index.php, and add following snippet (without php parenthesis) after drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

require_once 'includes/';
print user_hash_password('mynewpassword'); die();

Then visit your site, you'll get the hashed "mynewpassword", copy it, open index.php, revert your changes, update the database with the hash you got using following query:

UPDATE users SET pass='mynewhash' WHERE uid=1; 

And thats it, now you can login with your "mynewpassword"!