Automatic username generation How do I create a user registration form where username field cannot be modified by the user and is auto-generated on the basis of two other fields in form (dynamically).

I know there are some modules available for the task in Drupal 7, but how do I achieve this in Drupal 8?
This is pretty simple. Create your module, then create a form "MyRegForm" where the user can input her email and (if needed) password (twice with the '#type' => 'password_confirm'). Then, in the submit() method create your user like this:

\Drupal\user\Entity\User::create([
            'name' =&gt; 'hGzfT54re39OpLLLk',
            'pass' =&gt; 'hGzfT54re39OpLLLk',
            'mail' =&gt; $data-&gt;mail,
            'status' =&gt; 1,
            'init' =&gt; $data-&gt;mail,
            'created' =&gt; time(),
            'changed' =&gt; time(),
            'login' =&gt; 0,
            'access' =&gt; 0,
        ])-&gt;save();


The change the username and add whatever roles you need with code like

    $tuser = user_load_by_name('hGzfT54re39OpLLLk');
    $tuser-&gt;setUsername('My super name logic');
    $tuser-&gt;addRole("whatever");
    $tuser-&gt;save();
    $rc = $tuser-&gt;id();


If you don't want to create your own form for registration, go for hook_form_alter and set the #access to the "name" field to false and add a #default_value.