Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Aastha Shrivastava
Aastha Shrivastava

Posted on • Edited on

     

Resetting admin password in Drupal

Often when you are working on a local Drupal site you may forget your admin password and you haven't setup SMTP yet, in this case there are multiple ways to recover your admin password, this article we'll see how to reset the admin password bychanging password in database and resetting passwordusing drush.

Using SQL/Database

Prerequisite:

  • Access to your drupal site's codebase i.e the project folder of your drupal site
  • Access to database which is used by your drupal site

Generating password hash

  • Go to your site's document root and execute
php core/scripts/password-hash.sh 'newpasswd'
Enter fullscreen modeExit fullscreen mode

Replace'newpasswd' with your password.

You will see the output similar to this:

password: newpasswd         hash: $S$Eno1EhlPNMqE2RfDOBT13tzGCAdN9PgKqJFGI.4sBSj1XgJfPH68
Enter fullscreen modeExit fullscreen mode

$S$Eno1EhlPNMqE2RfDOBT13tzGCAdN9PgKqJFGI.4sBSj1XgJfPH68 is the hash which we need to update in the database.

Updating password in database

You can either use GUI like phpmyadmin and changepass =$S$Eno1EhlPNMqE2RfDOBT13tzGCAdN9PgKqJFGI.4sBSj1XgJfPH68 in theusers_field_data.

Theuid of admin is 1 by default in drupal. The same mechanism can be used to change password of any user by supplying the appropriateuid.

OR
You can use mysql command line and execute:

UPDATE users_field_data SET pass='$S$Eno1EhlPNMqE2RfDOBT13tzGCAdN9PgKqJFGI.4sBSj1XgJfPH68' WHERE uid = 1;
Enter fullscreen modeExit fullscreen mode

Clearing the cache

Even after updating the password inusers_field_data table,may still won't allow you to login this is because the login system is referring to the password stored incache_entity table and notusers_field_data, so you will need to delete the record incache_entity using gui, or by using mysql command line and executing:

DELETE FROM cache_entity WHERE cid = 'values:user:1';
Enter fullscreen modeExit fullscreen mode

For drupal 7 or older

Generating password hash

Go to your site's document root and execute

php scripts/password-hash.sh 'newpasswd'
Enter fullscreen modeExit fullscreen mode

Replace'newpasswd' with your password.

Updating password in database

You need to make the changes mentioned for Drupal 8 or newer inusers table instead ofusers_field_data

If you have exceeded your login attempts you may need to delete corresponding records fromflood table.
This flood table records username and ip which has failed login attempts.

Using Drush

If you havedrush installed with your drupal installation you can easily reset the password for any user even the admin

There are 2 ways of using drush to change password:

Using drush to generate password reset link

You can generate a link to reset with the following command:

drush uli --name=<username>
Enter fullscreen modeExit fullscreen mode

or

drush uli --uid=<user id>
Enter fullscreen modeExit fullscreen mode

Replace and with the username and the id of the user whose password needs to get reset. If you do not specifyuid orname drush will operate on the user withuid1.

This will generate aone-time login link which looks like this:
http://default/user/reset/2/1604915661/Ua9e50at_ggrlLqr5ulcX39CbpLjLO85Tczhz8nbdCM/login

Replacedefault with your hostname or IP and log in.

Alternatively, you can use option--uri <hostname/IP> to specify the hostname or IP of your website and drush will generate the link for your site.

Copy this link on your browser and you will get the password reset screen.

Using drush to reset password through the command line

You can change the password ofsomeuser tosomepass like this:

drush user:password someuser "somepass"
Enter fullscreen modeExit fullscreen mode

References:

Resetting the administrator password with sql-query in Drupal 8
Resetting the administrator password with sql-query (Drupal 7)
Recovering the administrator password

Top comments(1)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
sk335577 profile image
Sandeep Kumar
Follower of Cosmic God SHIVA!!
  • Location
    Chandigarh, India
  • Joined

It worked!! Thank you!

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

  • Location
    Pune, India
  • Joined

More fromAastha Shrivastava

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp