How can i import plain password that are not encrypted during a user migration? I am able to migrate all the datas of users account including the password but it doesn’t work due to encryption and hash in drupal 8.

My password are not MD5. They are not encrypted, in csv file they are like normal plain text.

I’ve seen here :
https://www.drupal.org/docs/8/api/migrate-api/migrate-destination-entityuser


  If the incoming passwords are not plain or are not MD5 hashed you'll
  have to deal with this in your migration


My password are plain so i guess it should work.

Here is what i’ve tried but the password are imported but not encrypted :

destination:
  plugin: 'entity:user'
  plaintext_passwords: true


In the documentation, it is explained how to import MD5 password but not plain password.

What should i use for the configuration ?



EDIT :

I’ve tried this :

pass:
    -
      plugin: callback
      callable: 'Drupal\Core\Password\PhpassHashedPassword::hash'
      source: passwebservice


And

pass:
    -
      plugin: callback
      callable:
        - 'Drupal\Core\Password\PhpassHashedPassword'
        - hash
      source: passwebservice


Error :


  Error: Using $this when not in object context in
  Drupal\Core\Password\PhpassHashedPassword::hash()  [error] (line 215
  of
  Core/Password/PhpassHashedPassword.php)
  0 [internal function]: Drupal\Core\Password\PhpassHashedPassword::hash('9BQmM1')
  1 core/modules/migrate/src/Plugin/migrate/process/Callback.php(54):
  call_user_func('Drupal\Core\Pas...', '9BQmM1')


When i check hash()

public function hash($password) {
    return $this-&gt;crypt('sha512', $password, $this-&gt;generateSalt());
  }


I can't invoke method this way ($this does not exist in class context) so how can I do ? Is it possible in configuration file ?
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-&gt;getSourceProperty('password');
    $hash = \Drupal::service('password')-&gt;hash($password);
    $row-&gt;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.

&lt;?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')-&gt;hash($value);
    return $hash;
  }

}