By Anonymous (not verified) on
Hi all,
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/us...)
<?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
Comments
Create a page named something
Create a page named something like rehash.php (in your root, same place as update.php) and copy in code below. Log in to Drupal site as administrator, browse to rehash.php.
Thanks to hross over @ stackoverflow (http://stackoverflow.com/questions/6205605/drupal-6-user-password-import...)
Well is this script still
Well is this script still working with last Drupal version?
I can"t make it work... stored hash is wrong.
[Edit] : printing the new_hash variable at the end of user_hash_password function shows a right hash, corresponding to the password. BUT, the hash stored is not the same... Is there a trigger in the database that can encrypt it again when saving???
Drupal rocks!
www.tahiticlic.com
Well it seems to work on
Well it seems to work on another install, I can't get why this didn"t work the first time.
Drupal rocks!
www.tahiticlic.com
Your D6 to D7 script worked great !
Just to say your (swilsondesign) "module" or rehash.php script worked great !
To be safe, I first copied the D6 table users over to the D7 table, renaming the table: old_users
( Done using the phpMyAdmin, with the Operations tab at the top of the D7 table.)
With your script, I can easily both (choice) convert the D6 table to a D7 compatible format* OR insert the old passwords (MD5) in the D7 users table with the new encryption (SHA1).
* Important note for Drupal webmasters out there :
If you use the method of converting the D6 passwords first (i.e. in the D6 database or in an imported old_users table), you must modify the pass field first: from the original varchar 32 to varchar 128. Otherwise the rehash.php will tell you that the destination field is too short to accept the new passwords.
Easier method : mind you, it is much simpler to just first import the pass field directly in the D7 users table and then run the rehash.php script.
Michael Lessard
webmaster of Quebec City "democracy in action" media
Unable to make it work
Hi,
I am migrating users from d6 to d7 using migrate module. I used the above specified logic or even tried adding $this->destination = new MigrateDestinationUser(array('md5_passwords' => TRUE)); which automatically saves the password with a 'U' appended.
http://drupal.org/node/1349758
But when i try to login using my old password, it says. Sorry, unrecognized username or password. Have you forgotten your password?
I didn't use any modules to
I didn't use any modules to migrate users. All i did was match db rows using a SQL import. When all the users are imported, run this script.
S
Why would having a U in front
Why would having a U in front of the hash make this work? Does Drupal see that and interpret the hash differently?
I have no idea! Taken from
I have no idea!
Taken from API http://api.drupal.org/api/drupal/modules--user--user.install/function/us...
S