[Drupal] Methods to reset Drupal user password without using admin panel
Here are the simple commands to reset the Drupal user/admin password without accessing the default administration page.
Reset password using PHP - With PHPMyAdmin Access
This method can be used during the development or while configuring local environment.
Execute the following commands:
cd <path_to_drupal_root_directory>
php scripts/password-hash.sh 'new_password'
On executing the above code, you will get a hashed string. Copy it, then go to PHPMyAdmin, or use any other MySQL client you have been using. Find the table 'users' and update the pass field with the obtained string. You can run query for all the entries or specific rows to reset the password, as you desire.
Please note that this method is recommended for production sites.
Reset password using Drush
Execute the following commands.
cd <path_to_drupal_root_directory>
drush upwd admin --password="new_password"
This method is simpler than the above-mentioned one. The new password get updated instantly in the database.
If you have any queries regarding the commands, please feel free to get in touch with us. Please look into other shell commands over here.