我们正在将我们的旧站点从普通PHP迁移到Drupal 8,密码在旧站点中使用MD5进行散列,我需要在Drupal中迁移它们。
我尝试了以下代码,但它接受密码作为纯文本,并计算其SHA哈希。
public function prepareRow(Row $row) {
$password = $row->getSourceProperty('user_password');
$hash = \Drupal::service('password')->hash($password);
$row->setSourceProperty('user_password', $hash);
}
这是配置文件。
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
发布于 2020-01-28 09:11:51
此简单代码在将md5密码迁移到drupal 8时运行正常。
$password_service = \Drupal::service('password');
$password = $row->getSourceProperty('user_password'); // 'user_password' is the old db column which is in md5 format
$hashed_password = 'U' . $password_service->hash($password); // U will indicate that the password needs rehashing.
$row->setSourceProperty('hash_password', $hashed_password);
发布于 2020-01-24 07:41:47
因为您不知道密码,只知道散列,所以不能直接迁移它。(MD5是弱的,但没有那么弱。)散列的全部目的是密码应该是任何人都不知道的,除了用户。有两种解决方案。
事实证明,Drupal会自动重新散列(请参阅UserAuth::authenticate()
),但对于MD5则不然,除非您用"U“前缀稍微修改现有散列。(谢谢d70rr3s和Souvik。)另见用户_更新_7000。
https://drupal.stackexchange.com/questions/290453
复制相似问题