This is the code I used to migrate old Drupal 6 user records to Drupal 8. I used the entity_type.manager service to create user entities.
$values = [
'name' => $data['name'],
'pass' => $data['pass'],
'mail' => $data['mail'],
'init' => $data['init'],
'status' => $data['status'],
'timezone' => $data['timezone_name'],
'created' => $data['created'],
'access' => $data['access'],
'login' => $data['login'],
'langcode' => $data['language'],
'preferred_langcode' => $data['language'],
'preferred_admin_langcode' => $data['language'],
];
if (!empty($data['picture'])) {
$file_remote_url = $remoteBaseUrl . $data['picture'];
$file_content = file_get_contents($file_remote_url);
$file_name = basename($data['picture']);
$file_uri = 'public://' . $file_name;
if (!empty($file_content)) {
$file = file_save_data($file_content, $file_uri, FILE_EXISTS_REPLACE);
if ($file) {
$values['user_picture'] = $file->id();
}
}
}
/** @var \Drupal\user\Entity\User $entity */
$entity = \Drupal::entityTypeManager()
->getStorage('user')
->create($values);
$entity->save();