gpt4 book ai didi

Drupal 6 用户密码导入 Drupal 7

转载 作者:行者123 更新时间:2023-12-04 11:43:42 25 4
gpt4 key购买 nike

除了用户之外,我真的不需要将任何数据导入到我的 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) {
// Indicate an updated password.
$new_hash = 'U' . $new_hash;
}
?>

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

谢谢,

史蒂夫

最佳答案

我认为您可以创建一个名为 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');

// 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,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6205605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com