How to migrate password with hash
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);
  }
}