We are migrating our old site from plain PHP to Drupal 8. Passwords are hashed with MD5 in the old site; I need to migrate them in Drupal.
I tried the following code, but it takes the password as plain text and calculates its SHA hash.
public function prepareRow(Row $row) {
$password = $row->getSourceProperty('user_password');
$hash = \Drupal::service('password')->hash($password);
$row->setSourceProperty('user_password', $hash);
}
This is the configuration file.
id: users
label: User migration
migration_group: mymodule_general_migration_groups
source:
plugin: mymodule_migration_users
process:
pass: user_password
mail: user_email
init: user_email
status:
plugin: default_value
default_value: 1
name:
plugin: dedupe_entity
source: username
entity_type: user
field: name
postfix: _
created:
plugin: callback
source: created
callable: strtotime
changed: user_regdate
access: user_regdate
login: user_lastvisit
destination:
plugin: entity:user
md5_password: true
migration_dependencies: {}
dependencies:
enforced:
module:
- mymodule_migration
hash()
don't encrypt text, but calculate the hash value, and by definition they are one-way functions. (It means there aren't inverse functions that from the hash return the original value.)