Resetting the admin password in Drupal 7 with SQL query

When, in Drupal 7, the password for user 1 (the administrator) is lost and the email notification or drush methods don’t work, it is possible to set the password via a database query.

Unlike Drupal 6 which uses MD5 hash passwords, in Drupal 7 you have to generate a SHA-512 salted password hash that is valid for your site.

To do this, execute the following commands from the command line, in the Drupal root directory:

./scripts/password-hash.sh

Of course, change “” to your new desired password. If the password contains special characters such as a space, * or ? you must escape them, or wrap the password in quotes appropriate for the shell used.

The script will output a password hash that is valid for the site. Copy this to the clipboard (these hashes look somewhat like) $S$Dt02xJ8TagYvnX4LKvrtTSsIkChsif4TAx7R6.KAzRb5ojreLSA

Then execute the following query on the Drupal database:

UPDATE users SET pass ='$S$Dt02xJ8TagYvnX4LKvrtTSsIkChsif4TAx7R6.KAzRb5ojreLSA' WHERE uid = 1;

Clear flood table

If you have reset password either by using script or “request new password” but still receive “Sorry, there have been more than 5 failed login attempts for this account. It is temporarily blocked.” then you may delete the corresponding entry in flood table.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s