Monday, 18 February 2013

Drupal 7 - Restoring the password via database

On Drupal 7, the password of any user is stored in the database as hash of it. It is in the column Pass of the table users. If it is needed to reset and there is not any other admin in the system, (and the mail service does not works), it could be set manually in the database.

1. Creates a new password hash
1.1 Open the folder of Drupal 7. Usually it is under htdocs/drupal7
1.2 Open the file index.php from any text editor
1.3 Add the follow code at the buttom of the php file

require_once 'includes/password.inc';
echo user_hash_password('a');
die();

1.4 Open the Drupal main web page. Usually it is


and the password's hash will appears on the buttom of the web page. For example, for the password a, it is:

$S$D8rBxmbI63KswZzFpWVMETfnoUoluLi7r.An3Yxp66dA/fxqMzO8

2. Set the password on the database
2.1 Open the phpMyAdmin. Usually it is


2.2 On the left panel, select the database of Drupal. Usually it is called Drupal7
2.3 On the left panel, select the table users
2.4 On the main screen, chose the row with the right user name. Click on the Column Pass and paste the hash of the new password
2.5 Click on Enter to save. You will see the message "One file has been updated"

Note: Don't forget to remove the added code on the step 1.3 to load correctly the main page of Drupal.

No comments:

Post a Comment