Login / Reset your Drupal account with Drush
Alexis Panagopoulos's picture

Login / Reset your Drupal account with Drush

Save your Friday

There are those Friday mornings, that your day starts when you receive a call from a very desperate client because she doesn’t remember what her Drupal password is and of course she doesn’t know what her username or email. OK nothing to worry about, you (think you) possess the admin credentials and you are 3-4 clicks away from resetting her password. But somehow the development team forget to sent you or write down the administrator password. So, you are in the bad position not only to unlock the admin account, but to ultimate help the client before ruining your morning.

For you to keep your TGIF status, all you have to do is to employ some Drush commands. You know Drush, right? In case you don’t, Drush is a command line shell and scripting interface for Drupal and it’s a prerequisite for every Drupal fellow out there.

So let’s start with our client request, in order to make her happy first. Using the following command we can specify her new password, while hearing her “screams”:

$ drush user-password [name] --password=”[password]”
$ drush upwd [name] --password=”[password]” #alias

The command requires two arguments: [name] where you specify the name of the account to modify and the [password] in plain text. Like we type it inside a password field. An example would be the following:

$ drush user-password client --password=”carpe diem”

Our client is happy and we managed to save our day :-).

In case our client doesn’t know her username and thus we need to login with the admin account we have to use the following command:

$ drush user-login
$ drush uli #alias

The above command displays a one time login link for the given user account (defaults to uid 1). For example, typing the above we get something like that:

$ http://default/user/reset/1/1381475875/k7MTClSsydKzjTHj2h5dwNIjxvKwiiqL_Zy8h3XOt7U/login

Which can be copied in our browser and we can login as admin in no time. This command can be used for our client as well, in case we somehow know her user id (uid) or her email. For example:

$ drush uli --uid=[uid] #The user id of the account
$ drush uli --name=[name] # Name of the account
$ drush uli --email=[email] # A user mail address to log in as

Additional information is available by typing drush help uli or drush help upwd accordingly.