I have a complete Drupal website on localhost. I forgot the password and username for my account. I found the username in the database, but the password is hashed.

I can't send emails from localhost, so recovering the password using the email is not possible.

How can I recover the password?

  • @AjitS no that is not, I have it on localhost and I can't send email from that!
    – user44925
    Commented Mar 9, 2015 at 5:35
  • Well, if you configure a SMTP client you can. But that is a different story!
    – AjitS
    Commented Mar 9, 2015 at 6:40
  • With drupal-7 you can do like this:goo.gl/zyQyzd Commented Apr 6, 2015 at 7:15

6 Answers 6


You can update the password via mysql. You can run the following query in mysql to update password. The given hashed value is the hashed value of password: NewPassword

UPDATE users SET pass = '$S$DRSUIz9NFfxOXKPveQ00UTGMzsJe62LjYvVHfYJ8I8wuy4zRqVBK' WHERE uid = 1;

For detailed instructions go through these article Resetting the administrator password with sql-query (Drupal 7)


If you are using Gnu/Linux or compatible, the simplest method with drush is this:

Install drush (if you haven't done so yet).

Go to your drupal-root/sites/mysite folder.

Type in the Gnu/Linux CLI:

sudo drush upwd --password="newpassword" admin

(where "admin" is the user name of user #1).

The password will now be "newpassword".

Alternatively, you can type in the Gnu/Linux CLI:

sudo drush uli

and use the URL it gives you to log in.


If you are using Linux:

  1. Install drush
  2. Go to your drupal-root/sites/mysite folder
  3. Type sudo drush uli and use the URL it gives you to log in.
  • Thanks, But I am using Windows. +1 for u
    – user44925
    Commented Mar 9, 2015 at 5:15

If you don't have Drush you could do:

  1. Edit your index.php in your Drupal site root

  2. Insert the code below between "drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);" and "menu_execute_active_handler();":

    require_once 'includes/password.inc';
    echo user_hash_password('CHANGE_THIS_TO_DESIRED_PASSWORD');

  3. Copy the hashed string

  4. Go to your database administration UI or phpmyadmin

  5. Go to the users table

  6. Find the admin user (mostly is the user with 1 as the uid)

  7. Update the admin's password field using the hashed string you just copied.

  8. Comment or delete the code in step 2

  9. Refresh your site and login

  • I tried this way but not working! each time that I refreshed the page the password that printed was changing
    – user44925
    Commented Mar 9, 2015 at 5:24
  • Ah! Just do it once and the string you replaced the CHANGE_THIS_TO_DESIRED_PASSWORD is the password you would use on login but hope your getting things sorted out already though. :) Commented Mar 9, 2015 at 5:28

The easiest way is to open the users table in phpmyadmin, in the password column, delete the content of the row of the admin username. In this way the password is deleted.

Open the database of another website in your localhost that you know the admin password, open the users table, in the password column, select the row of the admin user and copy its content to the admin row of users table of database of the website that you forget its password.

Notice that the passwords are saved in hash format in the database.


Just create a file "new_password.php" (or with any other name) inside your drupal folder and access it using browser. It will generate one way encrypted hash password for you.

  define("DRUPAL_ROOT", getcwd());
  require_once DRUPAL_ROOT . "/includes/bootstrap.inc";
  require_once "includes/password.inc";
  echo user_hash_password("123456");

When you run this code in browser it will show you hash password like


Now you need to update your database table using above hash. Open your database using PHPMyAdmin or Workbench and run the below query.

UPDATE users SET pass = '$S$D95YW4EejaUDPq5nZ7Z2Ljx1Ud4wlN1iTMQdAKton70JcQpCZmrG' WHERE uid = 1;

Now you can access drupal using username as "admin" and password as "123456". Make sure you update password after login to the admin.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.