Jojodae Ganesh Sivaji
October 16, 2012
I was a part of Learn Drupal on Global Drupal Training Day!, Drupal Chennai event to deliver a talk about installation and Drupal in general. The attendees were from different genres, but the majority of them were students. After the presentations, Shyamala propounded forming teams and letting the student participants try a Drupal installation and come up with a site of their own taste and novelty.
It was awesome to see the enthusiasm of the participants!! From a curious student, a relatively simple question was thrown at me. It was,
What if, we don't remember the password that we issued at the time of installation?
Of course, they knew it was a super admin account, and paramount needed credentials to access the site.
While it is pretty simple and being a developer we have done things of this sort every now and then, to understand the technical capabilities of students and answer from their perspective needs a little more skill. It took me a while to recollect the different paradigms to reset passwords, I'm jotting down the same in the blog post in the order of complexity,
Drupal user module ships with a native password reset mechanism. On all Drupal sites, the page https://example.com/user/password has a simple form that takes the username or email address of the user that wishes to reset his/her password. On form submission, the e-mail address bound to that user's account will receive an email with a one-time auto-login link and instructions to set a new password.
Every piece of content in Drupal goes in and out of the SQL database. The {user} table in the Drupal database maintains the password of users in an encrypted format. Prior to Drupal 7, md5() encrypted text was the preferred format to save passwords but now in Drupal 7, the salted sha512 hash is being used. The API wrapper function user_hash_password() returns the encrypted text for the given plain text password in Drupal 7.
The below SQL query would set the username and password of the super admin user (uid 1) to admin and drupal respectively.
For d6 : UPDATE users SET name='admin', pass=md5('drupal') WHERE uid = 1;
For d7 : UPDATE users SET name='admin', pass='$S$Drl0vgZ9yuU9uc4JyaTMHxMPriC7q/PsOUOx52fCrVQSTpI/Tu4x' WHERE uid = 1;
where $S$Drl0vgZ9yuU9uc4JyaTMHxMPriC7q/PsOUOx52fCrVQSTpI/Tu4x is the encrypted text for password drupal. To generate hash text for different plain text Drupal ships with a PHP script password-hash.sh, cd to the drupal root directory, and run the command "php scripts/password-hash.sh 'mynewpassword
'" from the command prompt to get the encrypted password.
Drush commands like upwd
or sqlq
can set a new password for a given account.
drush upwd admin --password=drupal
drush sqlq "update users set name='admin', pass='$S$Drl0vgZ9yuU9uc4JyaTMHxMPriC7q/PsOUOx52fCrVQSTpI/Tu4x' where uid = 1;"
The Drupal 7 user module ships with a special role administrator,
This is in addition to anonymous
and authenticated
user role. Administrator
role by default gets access to all the permissions exposed by all modules in Drupal. Creating new users and adding them to administrator
role and using the same to administer the site is considered as best security practice instead of using a single super admin account.
The global variable $user in Drupal represents the user object. It contains account information, logged-in status, etc. Altering $user appropriately can grant admin access to anyone accessing the site as needed. Adding the below snippet to any active module, say hook_exit() in overlay.module would grant super admin access to all the users accessing the site in a given time.
Among the approaches listed above #3 and #5 work from the file system level, i.e. even if we don't have a user account on the Drupal site the back doors in Drupal make it possible to avail admin access to the site with minimal effort.
Just like how your fellow techies do.
We'd love to talk about how we can work together
Take control of your AWS cloud costs that enables you to grow!