Programmatically create a user account
For Drupal 8, the code to create a user entity is the following one.

$language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();
$user = \Drupal\user\Entity\User::create();

// Mandatory.
$user-&gt;setPassword('password');
$user-&gt;enforceIsNew();
$user-&gt;setEmail('email');
$user-&gt;setUsername('user_name');

// Optional.
$user-&gt;set('init', 'email');
$user-&gt;set('langcode', $language);
$user-&gt;set('preferred_langcode', $language);
$user-&gt;set('preferred_admin_langcode', $language);
$user-&gt;set('setting_name', 'setting_value');
$user-&gt;addRole('rid');
$user-&gt;activate();

// Save user account.
$result = $user-&gt;save();


The code can be found on Create a user account programmatically in Drupal 8.