2 added 1285 characters in body
source | link

You can use Ivan Jaros' code in two ways:

As you said, preprocess your passwords to convert them to hashes. This can be done via a Drush script that can be run from the command line. Drush scripts are just snippets of PhP code that run in the Drupal context. Run by the command:

drush @site-alias scr [path to php snippet]

The alternative is to override you CVS Source class and use the preparerow method to hash the password.

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $password = $row->getSourceProperty('password');
    $hash = \Drupal::service('password')->hash($password);
    $row->setSourceProperty('password', $hash);
  }

As pointed out in the comments, you can also use a process plug-in to do this. The callback plugin only uses static classes and AFIAK the hash method requires access to the context information that is not available via static methods.

Here's some quick untested code to create your own process plug-in to hash a plain text password.

<?php

namespace Drupal\my_mode\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Converts a plain password to an hash.
 *
 * Example:
 *
 * @code
 * process:
 *   password:
 *     plugin: my_module_hash_password
 *     source: field_password
 * @endcode
 *
 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
 *
 * @MigrateProcessPlugin(
 *   id = "my_module_hash_password"
 * )
 */
class HashPassword extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $hash = \Drupal::service('password')->hash($value);
    return $hash;
  }

}

You can use Ivan Jaros' code in two ways:

As you said, preprocess your passwords to convert them to hashes. This can be done via a Drush script that can be run from the command line. Drush scripts are just snippets of PhP code that run in the Drupal context. Run by the command:

drush @site-alias scr [path to php snippet]

The alternative is to override you CVS Source class and use the preparerow method to hash the password.

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $password = $row->getSourceProperty('password');
    $hash = \Drupal::service('password')->hash($password);
    $row->setSourceProperty('password', $hash);
  }

You can use Ivan Jaros' code in two ways:

As you said, preprocess your passwords to convert them to hashes. This can be done via a Drush script that can be run from the command line. Drush scripts are just snippets of PhP code that run in the Drupal context. Run by the command:

drush @site-alias scr [path to php snippet]

The alternative is to override you CVS Source class and use the preparerow method to hash the password.

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $password = $row->getSourceProperty('password');
    $hash = \Drupal::service('password')->hash($password);
    $row->setSourceProperty('password', $hash);
  }

As pointed out in the comments, you can also use a process plug-in to do this. The callback plugin only uses static classes and AFIAK the hash method requires access to the context information that is not available via static methods.

Here's some quick untested code to create your own process plug-in to hash a plain text password.

<?php

namespace Drupal\my_mode\Plugin\migrate\process;

use Drupal\migrate\MigrateExecutableInterface;
use Drupal\migrate\ProcessPluginBase;
use Drupal\migrate\Row;

/**
 * Converts a plain password to an hash.
 *
 * Example:
 *
 * @code
 * process:
 *   password:
 *     plugin: my_module_hash_password
 *     source: field_password
 * @endcode
 *
 * @see \Drupal\migrate\Plugin\MigrateProcessInterface
 *
 * @MigrateProcessPlugin(
 *   id = "my_module_hash_password"
 * )
 */
class HashPassword extends ProcessPluginBase {

  /**
   * {@inheritdoc}
   */
  public function transform($value, MigrateExecutableInterface $migrate_executable, Row $row, $destination_property) {
    $hash = \Drupal::service('password')->hash($value);
    return $hash;
  }

}
1
source | link

You can use Ivan Jaros' code in two ways:

As you said, preprocess your passwords to convert them to hashes. This can be done via a Drush script that can be run from the command line. Drush scripts are just snippets of PhP code that run in the Drupal context. Run by the command:

drush @site-alias scr [path to php snippet]

The alternative is to override you CVS Source class and use the preparerow method to hash the password.

  /**
   * {@inheritdoc}
   */
  public function prepareRow(Row $row) {
    $password = $row->getSourceProperty('password');
    $hash = \Drupal::service('password')->hash($password);
    $row->setSourceProperty('password', $hash);
  }