I'm trying to migrate users from a non Drupal System into Drupal. I implemented my own CSV import script which basically generates Drupal user entities.

I already managed to teach Drupal how to handle the password hashes from the old system so that on first login of an "old" user, the old hash is getting replaced with a new one.

When creating a user account, Drupal automatically hashes the input for the Password field. I guess this is happening in the post save hook of the user entity.

How can I create user entities which will have my old hash inside of the pass field?

1 Answer 1


I figured it out by myself now. In case someone runs into the same problem: Updating the database directly avoids the problem of rehashing:

$query = \Drupal::database()->update('users_field_data')->fields([
    'pass' =>$prefixed_password_hash,


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.