Reset password after creating user account programmatically I'm creating a user account programmatically using the code below (Drupal 8). Everything works well except when the user suppose to change their password via the Drupal generated 'one-time login link'. The password reset doesn't work and it seems the 'pass-reset-token' is not generated properly. What am I doing wrong?

public function submitForm(array &amp;$form, FormStateInterface $form_state)
    {
        $the_user_email = $form_state-&gt;getValue('user_email');
        $the_user_name = $form_state-&gt;getValue('user_name');
        $language = \Drupal::languageManager()-&gt;getCurrentLanguage()-&gt;getId();        

        $user = \Drupal\user\Entity\User::create();
        $user-&gt;setPassword(user_password());
        $user-&gt;enforceIsNew();
        $user-&gt;setEmail($the_user_email);
        $user-&gt;setUsername($the_user_name); 
        $user-&gt;set("init", $the_user_email);
        $user-&gt;set("langcode", $language);
        $user-&gt;set("preferred_langcode", $language);
        $user-&gt;set("preferred_admin_langcode", $language);
        $user-&gt;addRole('price_list_users');
        $user-&gt;activate();

        //Create the account
        $user-&gt;save();     

        _user_mail_notify('register_no_approval_required', $user);

        drupal_set_message($this-&gt;t('A welcome message with further instructions has been sent to your email address.'));
        $form_state-&gt;setRedirect('/price-list');
    }
I guess you could utilize function user_pass_reset_url of user.module to generate reset link and send it via your custom _user_mail_notify function.

Generates a unique URL for a user to log in and reset their password.
Parameters
\Drupal\user\UserInterface $account: An object containing the user account.
array $options: (optional) A keyed array of settings. Supported options are:
langcode: A language code to be used when generating locale-sensitive URLs. If langcode is NULL the users preferred language is used.
Return value
string A unique URL that provides a one-time log in for the user, from which they can change their password.