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.

To change a Drupal user's password, you must first generate a password hash and then update the old password in the database.

  1. Generate a password hash using any of the methods:
    1. Connect to the hosting via SSH.
    2. 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 core directory in the project if the script directory has been moved there.

    3. Execute the command (replace new-password with the new password):
      scripts/password-hash.sh new-password
    1. In the site root directory, create a PHP script with the following content (replace new_password with 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();
      ?>
    2. Execute the script in the browser and the password hash will be displayed to you.
  2. Update the password in the database:
    1. In the configuration file of the site, check the name of the database to which it is connected.
    2. Open database in phpMyAdmin.
    3. Execute the following SQL query (replace hash_password with the obtained password hash, and also replace drupal_ with your table prefix if it differs from the standard):
      UPDATE `drupal_users_field_data` SET pass = '$hash_password' WHERE uid = 1;
  3. Check the login to the site admin panel.
  1. Connect to the hosting via SSH.
  2. Navigate to the site directory (use your own data in the command):
    cd /home/user/example.com/www/
  3. Change the password (replace NewPassword with the new password, and Username with the desired user):
    drush upwd --password=NewPassword Username
  4. Check the login to the site admin panel.
  1. In the configuration file of the site, check the name of the database to which it is connected.
  2. Open database in phpMyAdmin.
  3. Execute the following SQL query (replace new_password with the new password, and also replace drupal_ with your table prefix if it differs from the standard):
    UPDATE `drupal_user` SET pass = MD5('new_password') WHERE uid = 1;
  4. Check the login to the site admin panel.
Content