I am trying to migrate user accounts from a Drupal 7 site to a Drupal 8 site.

On the Drupal 8 site, I have a module that programmatically adds users using the following code.

$user = User::create();
$user->uid = '';
$user->set("pass", $S$E96L22SibwKw5GrZrrCqCz7mxSjr9Z2pSB3GqBs5eeheTBPxOlJc); /*hashed value*/

The module creates the accounts correctly, but the user passwords are re-hashed.

  • Don't hash the password in this line: $user->set("pass", $S$E96L22SibwKw5GrZrrCqCz7mxSjr9Z2pSB3GqBs5eeheTBPxOlJc);. Use an unhashed value. – Jaypan Sep 30 at 11:39
  • @Jaypan you are the right man. But I have 1000 user from my another drupal site. So that, I want to save hashed password. – Amit Senjaliya Sep 30 at 11:42
  • @Jaypan I know when a user saves with a password. drupal automatically convert plaintext to hashed – Amit Senjaliya Sep 30 at 11:44
  • It won't work - Drupal adds a hash salt to hashes, so unless you included that salt when creating your hashes, it wouldn't work. And since you are migrating your users from a different system, they won't have that salt. For this situation you can force your users to recover their password on the new system after migration, by sending out the password reset mail. – Jaypan Sep 30 at 11:45
  • @Jaypan No no, I have Drupal 7 sites so that is not a different system. When I have manually try drupal 7 passwords. it is worked. – Amit Senjaliya Sep 30 at 11:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.