How to migrate password with hash I'm doing a user migration from Drupal 7 to Drupal 8 (the data is in json format) 
Most of the fields have been imported to the new website. Now, I'm in the process to migrate the password; this field is, of course, encrypted/hashed (as far as I understood, Drupal uses SHA512 by default with a salt).
So far, I have found this answer and adapted my code like below:
$users_json = file_get_contents(&quot;../import/users.json&quot;);
$users_array = json_decode($users_json, true);

foreach($users_array as $user){

    $values = array(
        'name' =&gt; $user[&quot;name&quot;],
        'pass' =&gt; [
            'value' =&gt; $user[&quot;pass&quot;],
            'pre_hashed' =&gt; TRUE,
        ],
        'status' =&gt; $user[&quot;status&quot;],
        'mail' =&gt; $user[&quot;mail&quot;],
    );
    
    $userStorage = \Drupal::entityTypeManager()-&gt;getStorage('user');
    $userEntity = $userStorage-&gt;create($values);
    
    $role = $user[&quot;roles&quot;][0];
    $userEntity-&gt;addRole($role);

}

Now, my question is: Is it a good approach? How do I import this kind of field? Do I have to decrypt/de-hash the password?
You can follow document.

The $P$ is the so called hash type identifier which indicates that the
hash is a portable Phpass hash. The string after that consists of salt
and a hash. The portable Phpass hashes can be migrated to Drupal 8
as-is. When the user logs in to your Drupal 8 site for the first time,
Drupal will re-hash the password. The salted hash used in this example
is for a password 'test'.


If the source system was a PHP based application that used crypt() or
password_hash(), these hashes should work as-is and they can be
migrated 1:1 like in the Phpass example above. When the user logs in
to your Drupal 8 site for the first time, Drupal will re-hash the
password.

Here is my example convert old pass using md5
&lt;?php

namespace Drupal\my_module;

use Drupal\Core\Password\PhpassHashedPassword;
use Drupal\Core\Password\PasswordInterface;

/**
 * Provides custom password hash comparison for migrated passwords.
 */
class MyModulePasswordService extends PhpassHashedPassword implements PasswordInterface {


  public function check ($password, $hash) {
    // Check old pass is md5
    if (preg_match('/^[a-f0-9]{32}$/', $hash)) {
      $pwd_sercet = &quot;pwd_sercet&quot;;
      $pass_hash = md5($pwd_sercet . $password);
      return ($pass_hash == $hash);
    }
    return parent::check($password, $hash);
  }
}