Replacing an object of the UserLoginForm class with one of my own class Is it possible to replace an object of the UserLoginForm class with one of my own class?

What I want to do is replacing the login form with a custom one which would ask users to enter a code sent to their email address, once they entered the correct user credentials.

The problem is that an object of that class is created from UserController::userPage().

if ($user-&gt;id()) {
  $response = new RedirectResponse(url('user/' . $user-&gt;id(), array('absolute' =&gt; TRUE)));
}
else {
  $response = drupal_get_form(UserLoginForm::create($this-&gt;container), $request);
}


I know I can implement hook_form_alter() to alter the form, but I would like to use a class like UserLogin, and replacing $form_state['build_info']['callback_object'] with the object of my class in hook_form_alter() is probably too late.

Is it possible to use a class for altering the user login form? How?
As I said in the question, the problem was that UserController::userPage() expressly created an object of the class UserLoginForm. The method has been changed, and now it contains the following code, which doesn't contain any explicit reference to that class.

public function userPage() {
  return $this-&gt;redirect('entity.user.canonical', array('user' =&gt; $this-&gt;currentUser()-&gt;id()));
}


Using a route subscriber that extends RouteSubscriberBase is possible to change the form associated with a route.

use Drupal\Core\Routing\RouteSubscriberBase;
use Symfony\Component\Routing\RouteCollection;

class MymoduleRouteSubscriber extends RouteSubscriberBase {
  public function alterRoutes(RouteCollection $collection) {
    if ($route = $collection-&gt;get('user.login')) {
      $route-&gt;setDefault('_form', '\Drupal\mymodule\Form\MyModuleLoginForm');
    }
  }
}