Ste*_*son 7 passwords import md5 drupal
除了用户之外,我真的不需要将任何数据导入到我的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;
}
?>
Run Code Online (Sandbox Code Playgroud)
我在哪里可以运行此脚本以更新数据库中的密码字段?
谢谢,
史蒂夫
我认为你可以创建一个名为rehash.php的页面(在你的root中,与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();
}
}
?>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6481 次 |
| 最近记录: |