You are here

Different ways to change the Drupal password of admin account

When you install Drupal, it setup a first user admin account. This account is primarily used for doing all the administrative work on your site as a super user, of course you can create more users and give them admin rights but this first user with user id 1 will always have admin rights. Losing the password for this account can be very irritating especially if you didn't know how to reset your password, so let us discuss different ways to reset your admin account password.

Using Drush.

Drush provides an easy way to reset the password of your admin account. For this you need to use the command given below from within the Drupal directory.

drush upwd --password="newpassword" "admin"

Here admin is the username. If Drush is not installed on the server but you have mail server which is sending emails then try the next method.

Request new password via E-mail

You can reset your password by requesting a new password at http://www.example.com?q=user/password. If you don't have emails working on the server where Drupal is hosted then the next method can be used for that you need to have access to the server and its database.

Resetting the administrator password with sql-query.

If the above methods doesn't work you can directly change the password of your first user account in database. For this you need to have access to Drupal site database via command line or gui like phpmyadmin.

First you need to get the password in md5 format. For that run the following command in Drupal root directory. It will generate hash for you new password

  1. php ./scripts/password-hash.sh newpassword

Secondly after getting your password hash something like this "S$DYcd4qn4rXzC4YqPDcgcf.WyJVa4wutU8.dOj4fhiu4MF4O/v6FP" run the following sql command by connecting with your drupal database

  1. UPDATE users SET pass ='S$DYcd4qn4rXzC4YqPDcgcf.WyJVa4wutU8.dOj4fhiu4MF4O/v6FP' WHERE uid = 1;

In Drupal 7 this hash needs to be generated using the password-hash.sh command as this hash is only valid for the current site.

Following above steps will reset your password. So these were all the methods you can use for reseting your admin account password. I would recommend to use Drush method first because it is easy and the fastest.