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?
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
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:
sudo drush uliand use the URL it gives you to log in.
If you don't have Drush you could do:
Edit your index.php in your Drupal site root
Insert the code below between "drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);" and "menu_execute_active_handler();":
Copy the hashed string
Go to your database administration UI or phpmyadmin
Go to the users table
Find the admin user (mostly is the user with 1 as the uid)
Update the admin's password field using the hashed string you just copied.
Comment or delete the code in step 2
Refresh your site and login
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 filexc2xa0"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.
<?php define("DRUPAL_ROOT", getcwd()); require_once DRUPAL_ROOT . "/includes/bootstrap.inc"; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); require_once "includes/password.inc"; echo user_hash_password("123456"); die(); menu_execute_active_handler(); ?>
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.