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

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

问题描述

我真的不需要将任何数据导入我的D7构建而不是用户。我有(通过SQL)导入我的用户数据,但D7密码加密方法现在不同。



我不是任何想象力的专家,我我从来没有使用过Drush,但是我遇到这个user_update_7000代码片段,找到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){
//指示更新的密码。
$ new_hash ='U'。 $ new_hash;
}
?>

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



谢谢,



Steve

解决方案>

我想你可以创建一个名为类似rehash.php(在你的根目录,与update.php相同的地方)的页面。然后,以管理员身份登录,第二次浏览此页面。请参见下面的代码(大多数来自最新drupal 7安装中的user_update_7200)...



更糟的是,您可以创建一个简单的自定义模块,并将该代码放在那里。



请注意,您应该先备份

 <?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');

//低于DRUPAL_HASH_COUNT以使更新以合理的速度运行。
$ hash_count_log2 = 11;

//再次哈希所有当前散列的密码。
$ has_rows = FALSE;

//更新这个很多用户
$ 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){
//指示更新的密码。
$ new_hash ='U'。 $ new_hash;
db_update('users')
- > fields(array('pass'=> $ new_hash))
- > condition('uid',$ account-> uid )
- > execute();
}
}
?>


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.

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?

Thanks,

Steve

解决方案

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.

Please note that you should back things up first:

<?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天全站免登陆