Skip to main content
knackforge blog knowledge base

Yet another trick to reset Drupal admin password

Earlier I wrote a blog about different ways to reset admin password, one of those was using Drush. Sometimes you will need only momentary admin access to site. It happened recently to me when I had to deploy a new feature to live site but unaware of Drupal admin password, however I had command line access to server.


Drush is the most quick and efficient way to reset password in such cases. Also I don't want to reset the password permanently but provisionally, so that I can let the client use his preferred password when I'm done with my work. Here is how I thought it could be done.

First I figured the username and (encrypted) password of the administrator with drush sqlq command

$ drush sqlq "SELECT name, pass FROM users WHERE uid = 1;"
The output returned as below,
name pass
admin d69470a79b09b74f271b11b3c9d89be8

Then with drush upwd I did reset the password,

$ drush upwd admin --password=secretpassword

This gave me access to login & make the needed changes to site as super administrator user. Then I could restore the original password with drush sqlq command.

$ drush sqlq "update users set pass='d69470a79b09b74f271b11b3c9d89be8' where uid = 1;"

Here d69470a79b09b74f271b11b3c9d89be8 is encrypted password that I had noted down from the output of first drush sqlq command. Hope this will help others too, and could serve as a public documentation to our own team as well :)


Mike (not verified)

Wed, 01/16/2013 - 09:19

I've previously gone with creating a session and then changing the session table so the uid is set to 1 for that session id. No password changing required then.

Dave (not verified)

Wed, 01/16/2013 - 10:58

The `drush user-login admin` command or it's alias `drush uli admin` will display a one-time login URL to login the specified account. The output is a URL like: http:///user/reset/1/1358351267/WvqBsED_WKGeThnoY67SCRddVfpGymDaA1w1GP7ZTtP. After logging in using this URL, the user it NOT required to change the password. Also, disappointingly, this command only works with a username and not a uid. So if you try `drush uli 1` it will complain the user account with name 1 could not be loaded.

greg.1.anderson (not verified)

Wed, 01/16/2013 - 11:28

If you use the command `drush user-login`, it will print out a one-time login link that you can use to log in as the user with uid=1. Make sure that you log out of the site before you use the link, or Drupal will print an error message. You don't need to know the name of the admin user, and the password is not changed, so there's nothing that needs to be fixed up after you're done.

Matt (not verified)

Wed, 01/16/2013 - 11:52

"drush uli [username]" is the fastest way to do what you are doing above. Gives you a one time log in link without touching the previous password stored in the db. You can get in and do what you need and the client's access wont be interrupted.

Owen Barton (not verified)

Thu, 01/17/2013 - 01:32

You might want to check out this command:

user-login (uli) Display a one time login link for the given user account (defaults to uid 1).

This can log you in as the admin without you needing to even set a temporary password (or save the old one), which it seems is your intent here. Although you will be prompted to change your password, you are not required to.

If you run Drush 6.x-dev with a local sandbox it will even pop up a browser for you, log you in and open to a path specified on an argument with no other typing needed :)