在drupal 7中更改管理员密码

The*_*Man 4 drupal drupal-7

我使用内置的Drupal 7用户模块,用户注册,忘记密码 - 电子邮件和所有这些东西.

我忘记了我的管理员密码.我可以访问我的网站,该网站托管在1and1.com上,并且还可以访问mysql?

是否可以通过SQL更改密码或电子邮件地址,以便我可以访问管理页面?

如果有可能如何?你能帮助我吗?

谢谢!

Aji*_*t S 6

如果安装了Drush,则只需在站点根目录内的任何位置在终端中输入以下命令.

drush upwd admin --password=mynewpassword
Run Code Online (Sandbox Code Playgroud)

admin是用户名; 谁的密码将被更改为mynewpassword.


The*_*Man 6

经过几次研究,我尝试将以下代码存储在根目录下的php文件中

将其保存为password-reset-admin.php

<?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' => '<a href="mailto:yourmail@domain.com'">yourmail@domain.com'</a>;
))
->condition('uid', '1', '=')
->execute();
print "Done. Please delete this file immediately!";
drupal_exit();
 ?>
Run Code Online (Sandbox Code Playgroud)

然后通过以下方式访问php文件:

 https://yoursite.com/password-reset-admin.php?pass=newpassword
Run Code Online (Sandbox Code Playgroud)

它只是工作.. :)希望它有助于其他人.

请确保删除该文件.