Skip to content

Instantly share code, notes, and snippets.

@kane-thornwyrd
Created January 31, 2012 14:34
Show Gist options
  • Save kane-thornwyrd/1710797 to your computer and use it in GitHub Desktop.
Save kane-thornwyrd/1710797 to your computer and use it in GitHub Desktop.
Migrer les mots de passe de D6 à D7
<?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();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment