Reset a Drupal password

by Gisle Hannemyr

This page provides instructions for how to reset a password for any user account on a website powered by Drupal.

Table of contents

Introduction

If you have forgotten your Drupal user account password, you can regain access by resetting it. You can do so in a number of ways. This recipe page describes three different methods for doing so:

  1. Use email.
  2. Use drush.
  3. Hack the database.

Method 1 – use email

Provided your site is able to send email, and you have access to the mailbox for the email associated with the account, you can use the following to reset the account password:

  1. Open the Drupal login page, the path is “/user”.
  2. Click on “Reset your password” tab, or go directly to the password reset page, the path is “/user/password”.
  3. Enter the email address or username of the user you want to reset the password for, and press “Submit” or “E-mail new password”.
resetpwform.png
Figure 18-1: Resetting the password for the account “admin”.
  1. Check your email (including the spam folder) and locate the email that has been set. See example in the screenshot below.
resetpwmail.png
Figure 18-2: Example of an email with the link to reset the password.
  1. Login to the website using one-time login link provided in the email.
  2. You should now arrive at a form with fields to enter a new password. Enter new password and save.

noteIf you've made too many failed attempts (the default is 5) to login, Drupal will temporary block you and will not send you the email to reset the password. The blocking may last up to six hours. See Drupal Answers: How long does it take for Drupal to unblock user after 5 failed attempts? for how to resolve this without waiting.

Method 2 – use drush

If your site is unable to send email, or you do not have access to the email mailbox associated with the user you want to reset the password for, but you have access to the CLI on the web server hosting the site, you can use drush to change the password for any user from the command line. To change the password of the user with username “admin” into “NewPassword”, do as follows:

Drupal 10 or later:

$ drush upwd admin NewPassword
 [success] Changed password for admin.

Drupal 7:

$ drush upwd admin --password="NewPassword"
Changed password for admin.

You may also use drush to generate one-time login link. For the “--uid” option, use the integer uid for the user you want to reset the password for. In the example below, we use 1 (i.e. the superadmin). Replace “https://example.com” with the URL of your website.

$ drush user-login --uid=1 --uri=https://example.com
https://example.com/user/reset/1/1632984667/O1623SvMYJ96yPgT8vtnMR4pnU3EyxzPeVU/login

Copy and paste the one-time login link generated into the URL field of your browser.

Method 3 – hack the database

If you're unable to use email (option 1) and do not have access to drush (option 2) you can still reset the password provided you have access to the database and a database management tool (e.g. phpMyAdmin, Sequel Pro, TablePlus, and many others.

You'll find the username and a salted password hash in the table {users_field_data} (Drupal 10 or later), or on the table {users} (Drupal 7), in the fields “name” and “pass”. Locate an account where you already know the password, or create a new one.

Then, using the database management tool, copy the salted hash from the account where you know the password, and paste it into the “pass” field of the the account you want to reset the password for. You should now be able to login to the account using this password.

Final word

In addition to the three methods described above, there may exist contributed Drupal modules that may assist you in doing a password reset. I haven't explored this area yet, but you want to search for such modules in none of the methods described here works for you.

See alsoSee also: dev.to: Resetting admin password in Drupal.


Last update: 2021-01-17.