You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

新手求助:Drupal 7管理员账号无法登录如何解决

如何登录Drupal 7项目的管理员账号

Hey there, let's get you back into your Drupal 7 admin account—no need to stress, we've got a few solid ways to fix this. The reason your earlier attempts to edit the users table didn't work is that Drupal 7 stores hashed passwords, not plain text. Here's what you can do:

方法1:用Drush命令(最便捷,如果你有Drush)

Drush is Drupal's go-to command-line tool, and this is the fastest fix if it's installed on your server:

  • Navigate to your Drupal project's root directory via SSH or terminal
  • Run this command, replacing admin with your actual admin username and your-new-password with the password you want:
    drush upwd admin --password="your-new-password"
    
  • That's it! You can now log in with the new password right away.

方法2:手动生成密码哈希并更新数据库

If you don't have Drush, you can generate a valid password hash manually and update the database:

  1. Generate the password hash:
    • Create a new PHP file named generate_hash.php in your Drupal root directory, with this code:
      <?php
      require_once './includes/password.inc';
      $new_password = 'your-desired-password';
      $hash = user_hash_password($new_password);
      echo $hash;
      ?>
      
    • Replace your-desired-password with the password you want, then visit http://your-site-domain/generate_hash.php in your browser. Copy the hash string that appears on the page.
  2. Update the database:
    • Log into your MySQL database (via phpMyAdmin, command line, or your hosting control panel)
    • Locate your Drupal database, open the users table
    • Find the row for your admin user (usually has uid = 1)
    • Replace the value in the pass column with the hash string you copied
    • Save the changes, then log in with your admin username and new password

方法3:临时强制登录(紧急情况用)

This is a quick workaround to get into the admin panel immediately—just remember to revert the change after you set a proper password:

  • Open the sites/default/settings.php file in your Drupal root directory
  • Add this code at the very end of the file:
    function force_admin_login() {
      global $user;
      $user = user_load(1); // Replace 1 with your admin user's UID if it's different
      drupal_session_regenerate();
    }
    force_admin_login();
    
  • Save the file, then visit your website—you'll be automatically logged in as the admin
  • Immediately remove this code once you're in, then go to Account > Edit to set a new, secure password

Pro tip: Always back up your database and files before making changes like this, just to be safe!

内容的提问来源于stack exchange,提问作者Abhilash

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:17:04