Drupal 6 用户密码导入 Drupal 7 [英] Drupal 6 user password import to Drupal 7

查看:20
本文介绍了Drupal 6 用户密码导入 Drupal 7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

除了用户之外,我真的不需要将任何数据导入到我的 D7 版本中.我已经(通过 SQL)导入了我的用户数据,但是 D7 密码加密方法现在不同了.

I don't really need to import any data into my D7 build other than users. I have (by SQL) imported my user data however, the D7 password encryption method is now different.

我不是任何想象力的专家,我从未使用过 Drush,但我遇到过这个 user_update_7000 代码片段,发现 user.install (http://api.drupal.org/api/drupal/modules--user--user.安装/功能/user_update_7000/7)

I'm not an expert by any stretch of the imagination and I've never used Drush, but I have come across this user_update_7000 code snippet found user.install (http://api.drupal.org/api/drupal/modules--user--user.install/function/user_update_7000/7)

<?php
require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
$old_hash = md5('password');
$hash_count_log2 = 11;

$new_hash = user_hash_password($old_hash, $hash_count_log2);

if ($new_hash) {
  // Indicate an updated password.
  $new_hash  = 'U' . $new_hash;
}
?>

我可以在哪里运行此脚本以更新数据库中的密码字段?

Where could I run this script in order to update the password field in my DB?

谢谢,

史蒂夫

推荐答案

我认为您可以创建一个名为 rehash.php(在您的根目录中,与 update.php 相同的位置)的页面.然后,首先以管理员身份登录,然后浏览到此页面.请参阅下面的代码(大部分取自最新的 drupal 7 安装中的 user_update_7200)...

I think you can create a page named something like rehash.php (in your root, same place as update.php). Then, log in as administrator first, browse to this page second. See code below (most taken from user_update_7200 in the latest drupal 7 install)...

更糟糕的情况是,您可以创建一个简单的自定义模块并将此代码放入其中.

Worse case, you could create a simple custom module and put this code in there.

请注意,您应该先备份数据:

<?php
    // bootstrap stuff
    define('DRUPAL_ROOT', getcwd());

    include_once DRUPAL_ROOT . '/includes/bootstrap.inc';
    drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

    require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');

    // Lower than DRUPAL_HASH_COUNT to make the update run at a reasonable speed.
    $hash_count_log2 = 11;

    //  Hash again all current hashed passwords.
    $has_rows = FALSE;

    // Update this many users
    $count = 1000;

    $result = db_query_range("SELECT uid, pass FROM {users} WHERE uid > 1 ORDER BY uid", 0, $count);
    foreach ($result as $account) {
      $has_rows = TRUE;
      $new_hash = user_hash_password($account->pass, $hash_count_log2);
      if ($new_hash) {
        // Indicate an updated password.
        $new_hash  = 'U' . $new_hash;
        db_update('users')
          ->fields(array('pass' => $new_hash))
          ->condition('uid', $account->uid)
          ->execute();
      }
    }
?>

这篇关于Drupal 6 用户密码导入 Drupal 7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆