Manage cookies that are used for advertising, such as ad personalization, remarketing, and ad effectiveness analysis.
2.14.5.5. Change administrator password in Drupal
It is technically impossible to find out the current administrator password, as it is not stored on the site in plain text — only its hash is stored. Only a password reset to a new one is possible.
Drupal 7 and newer
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.
- Generate a password hash using any of the methods:
- Connect to the hosting via SSH.
- Navigate to the site directory (use your own data in the command):
cd /home/user/example.com/www/In some cases, it may be necessary to navigate to the
coredirectory in the project if the script directory has been moved there. - Execute the command (replace
new-passwordwith the new password):scripts/password-hash.sh new-password
- In the site root directory, create a PHP script with the following content (replace
new_passwordwith the 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 the password hash will be displayed to you.
- Update the password in the database:
- In the configuration file of the site, check the name of the database to which it is connected.
- Open database in phpMyAdmin.
- Execute the following SQL query (replace
hash_passwordwith the obtained password hash, and also replacedrupal_with your table prefix if it differs from the standard):UPDATE `drupal_users_field_data` SET pass = '$hash_password' WHERE uid = 1;
- Check the login to the site admin panel.
Drush
See Install Drush.
- Connect to the hosting via SSH.
- Navigate to the site directory (use your own data in the command):
cd /home/user/example.com/www/ - Change the password (replace
NewPasswordwith the new password, andUsernamewith the desired user):drush upwd --password=NewPassword Username - Check the login to the site admin panel.
Drupal up to version 7
- In the configuration file of the site, check the name of the database to which it is connected.
- Open database in phpMyAdmin.
- Execute the following SQL query (replace
new_passwordwith the new password, and also replacedrupal_with your table prefix if it differs from the standard):UPDATE `drupal_user` SET pass = MD5('new_password') WHERE uid = 1; - Check the login to the site admin panel.