How to reset admin password in drupal
Assuming that a) using the email to request the new password isn’t an option AND b) you have access to mysql or phpMyAdmin you may use the following methods to recover the password for your drupal root user:
drupal 6:
In drupal 6 the password is stored as a simple MD5 hash of your plain text password. Use this SQL to change the admin (i.e. the user with uid=1) password:
UPDATE users SET pass = MD5('newpass') WHERE uid=1;
drupal 7:
In drupal 7 the password is a ‘salted’ sha512 hash. The easiest method is (aside from using the drush ‘upwd’ command, which is easy enough but setting up drush may not be, especially on Windows.. so we’ll discuss this last, see below):
- Open your index.php file in a text editor
- Find this command:
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
- Insert below it the following lines:
require_once 'includes/password.inc'; echo user_hash_password('newpass'); die();
- Save the file.
- Open your site in a browser. You will get a blank page with only your hashed password string at the top.
- Copy the string.
- Open the DB in mysql or phpMyAdmin
- In table users set the pass field to this hash. For mysql this means use the same SQL command as for the drupal 6 example, but don’t use the MD5 function as the password was already hashed by the user_hash_password function.
- Edit index.php again and remove your changes
- Save
Open the site and login with the new password (‘newpass’ in this example or whatever you chose your new password to be).
Clear the flood table if necessary
You will need to clear the flood table if after resetting the password you get the following error when trying to login with new password:
‘There have been more than 5 failed login attempts […] account temporarily blocked’
This will happen on drupal 7 if you enter a wrong password more than 5 times. Not sure if also applies to drupal 6, probably yes.
At any rate, if you get this message you may wait 6 hours and then login (pfa!) OR go to phpMyAdmin or mysql again and:
DELETE * FROM flood;
Resetting drupal admin password with drush
As mentioned above, if you have drush then all of this (except maybe clearing the flood table) could be solved by one drush command:
drush upwd admin --password=newpass
2 Responses to How to reset admin password in drupal
Leave a Reply Cancel reply
-
Categories
- Android Development
- Bash
- C programming
- dpkg/apt-get
- drupal
- Emacs
- Git
- Java
- Linux administration
- Linux device drivers
- Linux Gaming
- Linux kernel
- Linux Networking
- Linux on Windows
- Linux printing
- Linux sound and ALSA
- Package Managers
- Programming
- RPM
- Shell and environment
- Tips and tricks
- Uncategorized
- VirtualBox
- Virtualization
- web development
- wine
- WMaker
- Wordpress Tips
- X Window System
- XFCE
-
Articles
- August 2020
- August 2019
- May 2019
- July 2017
- February 2017
- January 2017
- November 2016
- October 2016
- September 2016
- August 2016
- July 2016
- June 2016
- April 2016
- March 2016
- December 2015
- November 2015
- September 2015
- June 2015
- May 2015
- April 2015
- March 2015
- February 2015
- January 2015
- December 2014
- October 2014
- February 2014
- January 2014
- November 2013
- October 2013
- June 2013
- April 2013
- March 2013
- February 2013
- January 2013
- December 2012
- October 2012
- August 2012
- July 2012
- June 2012
- May 2012
- April 2012
- March 2012
- February 2012
- September 2011
- August 2011
- June 2011
- May 2011
- April 2011
- March 2011
- February 2011
-
Meta
Cloud
audio bash boot compile C programming cups drupal emacs etc Fedora git grep how to httpd init kernel libc linux linux partition localtime login make mount mp3 mysql networking oracle package managers password phpMyAdmin programming rpm shell sql vbox version control system virtual box vm web server wordpress www xargs xfce xwin yum
Thanks a lot for the D7 instructions.
BTW you missed a “;” at the end of
require_once ‘includes/password.inc’
Thanks! Corrected 🙂