欢迎各位兄弟 发布技术文章

这里的技术是共享的

You are here

drupal6 升级 upgrade 迁移到 drupal7 密码 保持密码不变 How do I migrate users passwords from Drupal 6 to Drupal 7? 有大用 有大大用

5 Answers 正确答案 

To update the md5 password to the hashed one I needed to use user_hash_password() and concact an 'U'. Here is the script that I used to make it work.

<?php
        require_once DRUPAL_ROOT . '/' . variable_get('password_inc', 'includes/password.inc');
        $res = db_query('select * from drupal.users');

        if($res) {
                foreach ($res as $result) {
                        $hashed_pass = user_hash_password($result->pass, 11);
                        if ($hashed_pass) {
                          $hashed_pass  = 'U' . $hashed_pass;
                          db_update('users')->fields(array('pass' => $hashed_pass))->condition('uid', $result->uid)->execute();
                        }
                }
        }

Then I ran

drush scr <name_of_the_script_file>

And it worked.

shareimprove this answeredited May 23 '11 at 14:49answered Apr 13 '11 at 15:50João Guilherme1,15821217

   Is 11 as the iteration count a standard D6 thing? – Sam152 Feb 15 '13 at 1:33

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();
      }
    }?>
shareimprove this answeredited Jun 1 '11 at 20:16answered Jun 1 '11 at 19:02hross2,97321729

1 Worked perfectly, thank you! One thing I needed to edit was the SQL on line 19... If anyone else uses this uid should be greater than 1 to avoid rehashing the admin password. – Stephen Wilson Jun 1 '11 at 19:34 1 Good point =). Updated. – hross Jun 1 '11 at 19:56   I think you meant user_update_7000, not user_update_7200 – aaronbauman Jun 23 '16 at 16:37

来自 https://drupal.stackexchange.com/questions/2279/how-do-i-migrate-users-passwords-from-drupal-6-to-drupal-7


来自  https://stackoverflow.com/questions/6205605/drupal-6-user-password-import-to-drupal-7

普通分类: