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.

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

  1. Connect to SSH hosting and navigate to your Drupal site directory. You can change the directory using the command:
    cd /home/user/example.com/www/

    Change user on title your hosting account, example.com/www — to the name of your subdomain where Drupal is installed.

  2. Run the command:
    scripts/password-hash.sh new-password

    Instead new-password enter the desired new password.

  1. 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();
    ?>
  2. Execute the script in the browser and you will see the hash of the password.

Updating the password in the database

  1. In the site config file takealook the name of the database to which it is connected.
  2. Openup database in phpMyAdmin.
  3. 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.

  4. Check the login to the admin panel.
Drush is installed by instruction.
  1. Connect to SSH hosting and navigate to your Drupal site directory. You can change the directory using the command:
    cd /home/user/example.com/www/

    Change user on title your hosting account, example.com/www — the name of your subdomain where Drupal is installed.

  2. Run the command to change your password:
    drush upwd --password=NewPassword Username

    On the team: instead of NewPassword enter a new password instead of Username — the desired user.

  3. Check the login to the admin panel.
  1. In the site config file takealook the name of the database to which it is connected.
  2. Openup database in phpMyAdmin.
  3. 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.

  4. Check the login to the admin panel.
Content