There are several methods to recover the Drupal administrator ("user 1") password. DrupalConsole and drush provide commands to recover and manage users passwords. If you do not use DrupalConsole or drush you can recover the password via mail.
Recover password with DrupalConsole
DrupalConsole offers several ways of recovering the administrator's password.
Generate login-link
DrupalConsole can generate a one-time login link.
drupal user:login:url
Reset password
drupal user:password:reset
Clear login failed attempts for an account.
drupal user:login:clear:attempts
Recover password with Drush
Drush offers several ways of recovering the administrator's password.
Generate login-link
Drush can generate a one-time login link.
drush uli
Reset password
drush upwd --password="givememypasswordback" "admin"
drush 9:
drush upwd admin "admin123"
(where "admin" is the user name)
Depending on your environment or hosting provider, you may or may not be able to use certain special characters as part of your username or password. For example on Pantheon, Pantheon SSH (which both Terminus and Drush @pantheon aliases use) explicitly rejects any command string that contains certain characters in any position, regardless of quoting or escaping.
The excluded characters are:
;$!`
Change password with a database query
Drupal 7
Update administrator password via sql-query in Drupal 7.
Drupal 6 and below
Execute the following query on the Drupal database where 'givememypasswordback' is your new password. You will need to log into your database using phpMyAdmin or another tool.
UPDATE users SET pass = MD5('givememypasswordback') WHERE uid=1;
Request new password via e-mail
You can reset your password by requesting a new password at:
http://www.example.com/user/password
or
http://www.example.com?q=user/password
.
You may need to find out the details with the following sql statement: select name, mail from users_field_data where uid = 1;
When User Blocked because of Maximum attempts
When you tried several time with wrong password drupal will blocked the user.
Drupal store the wrong attempts on the flood table.
To unblock the user you need to clear the data of flood table. To do so using drush run the following command:
drush sqlq "DELETE FROM flood"
Then run
drush upwd --password="mypassword" "admin"
Comments
updating password of a user using drush command line
I am using the drush 9.6.2 and I have done the following things to change admin or any other user passwod,
Run this command in drush command line,
drush upwd admin "admin123"
- Replace admin with the username for which you want to change the password and "admin123" will be the new password.
The you can clear the flood table [ it for too many attempts drupal login is blocked]
Run : drush sqlq "Truncate flood"
Now you are fine to login with the new password.
How can I reset a user's
How can I reset a user's password without Drush? I am on a shared hosting. (And without reset password because I forgot the email that I used for the Admin)
you can see your email with
you can see your email with this SQL ( on Drupal 10)
select name,mail from users_field_data;