2.13.5.5. Changing admin password in Drupal
It is technically impossible to find out the current administrator password, since it is not stored on the site in clear text — only its hash is stored. It is only possible to replace the password with a new one.
Drupal 7 and newer
Using a SQL query
To change a Drupal user's password, you must first generate a password hash and then update the old password in the database.
Generating a password hash
- Run the command:
scripts/password-hash.sh new-password
Instead
new-password
enter the desired new password.
- V root directory site, create a PHP script with content, specifying in it instead of
new_password
New Password:<?php define('DRUPAL_ROOT', getcwd()); require_once DRUPAL_ROOT . '/includes/bootstrap.inc'; drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); require_once 'includes/password.inc'; echo user_hash_password('new_password'); die(); menu_execute_active_handler(); ?>
- Execute the script in the browser and you will see the hash of the password.
Updating the password in the database
- In the site config file takealook the name of the database to which it is connected.
- Openup database in phpMyAdmin.
- Execute the following SQL query, instead of
hash_password
received password hash:UPDATE `drupal_user` SET pass = '$hash_password' WHERE uid = 1;
If the names of the tables in the database do not start with the standard
drupal_
, and with a different prefix, make the appropriate change to the SQL query. - Check the login to the admin panel.
With Drush
Drush is installed by instruction.
- Run the command to change your password:
drush upwd --password=NewPassword Username
On the team: instead of
NewPassword
enter a new password instead ofUsername
— the desired user. - Check the login to the admin panel.
Drupal prior to version 7
- In the site config file takealook the name of the database to which it is connected.
- Openup database in phpMyAdmin.
- Execute the following SQL query, instead of
new_password
New Password:UPDATE `drupal_user` SET pass = MD5('new_password') WHERE uid = 1;
If the names of the tables in the database do not start with the standard
drupal_
, and with a different prefix, make the appropriate change to the SQL query. - Check the login to the admin panel.