This snippet will be helpful if you don’t have command-line access to the
server to run the password-hash.sh shell file or no Drush access. In most shared
hosts, command-line access is not provided.
Please keep in mind that leaving the code below on your server after resetting the password is highly critical security problem that anyone can reset your administrator password. Use this carefully.
All we are going to do is, bootstrapping Drupal, getting the necessary functions that generates the password and then updating the database with new password.
First, create a file with a random name (gh34tu9.php for example) and put the following content in it.
Save it and upload it to the root of the Drupal installation folder (where
index.php, update.php, robots.txt and other files and folders exists).
Then, request the file in a browser tab in following syntax.
In the above URL,
- replace example.com with your actual domain name.
- replace gh34tu9.php with the actual file name of the file that you put the above content in.
- mypassword with your new password.
Upon successful run, you will see a the text “Done” in page and password of the user/1 account (the account you created when installing Drupal) changed to the mypassword.
Please keep in mind that leaving the code below on your server after resetting the password is highly critical security problem that anyone can reset your administrator password. Use this carefully.
All we are going to do is, bootstrapping Drupal, getting the necessary functions that generates the password and then updating the database with new password.
First, create a file with a random name (gh34tu9.php for example) and put the following content in it.
<?php
define('DRUPAL_ROOT', getcwd());
require_once
DRUPAL_ROOT .
'/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
require_once
DRUPAL_ROOT . '/includes/password.inc';
if (isset($_GET['pass']) &&
!empty($_GET['pass'])) {
$newhash =
user_hash_password($_GET['pass']);
}
else {
die('Retry with
?pass=PASSWORD set in the URL');
}
$updatepass = db_update('users')
->fields(array(
'pass' =>
$newhash,
// 'name' => 'admin',
// 'mail' =>
'yourmail@example.com'
))
->condition('uid', '1', '=')
->execute();
print "Done. Please delete this file
immediately!";
drupal_exit();
?>
Then, request the file in a browser tab in following syntax.
http://example.com/gh34tu9.php?pass=mypassword
In the above URL,
- replace example.com with your actual domain name.
- replace gh34tu9.php with the actual file name of the file that you put the above content in.
- mypassword with your new password.
Upon successful run, you will see a the text “Done” in page and password of the user/1 account (the account you created when installing Drupal) changed to the mypassword.
Comments
Post a Comment