How to check whether a username already exists?
I guess you can use a simple EntityQuery.

  $ids = \Drupal::entityQuery('user')
        -&gt;condition('name', 'USERNAME_TO_CHECK')
        -&gt;range(0, 1)
        -&gt;execute();
    if(!empty($ids)){
      //then this name already exists
    }