diff --git a/include/class.auth.php b/include/class.auth.php
index 39498a474578f4c87bf4f77bac651408421de4c5..313e1a476e7c556ef2a70ea72888ee77bcc38b97 100644
--- a/include/class.auth.php
+++ b/include/class.auth.php
@@ -86,6 +86,34 @@ class ClientCreateRequest {
     function getInfo() {
         return $this->info;
     }
+
+    function attemptAutoRegister() {
+        global $cfg;
+
+        if (!$cfg)
+            return false;
+
+        // Attempt to automatically register
+        $this_form = UserForm::getUserForm()->getForm($this->getInfo());
+        $bk = $this->getBackend();
+        $defaults = array(
+            'timezone_id' => $cfg->getDefaultTimezoneId(),
+            'dst' => $cfg->observeDaylightSaving(),
+            'username' => $this->getUsername(),
+        );
+        if ($bk->supportsInteractiveAuthentication())
+            // User can only be authenticated against this backend
+            $defaults['backend'] = $bk::$id;
+        if ($this_form->isValid(function($f) { return !$f->get('private'); })
+                && ($U = User::fromVars($this_form->getClean()))
+                && ($acct = ClientAccount::createForUser($U, $defaults))
+                // Confirm and save the account
+                && $acct->confirm()
+                // Login, since `tickets.php` will not attempt SSO
+                && ($cl = new ClientSession(new EndUser($U)))
+                && ($bk->login($cl, $bk)))
+            return $cl;
+    }
 }
 
 /**
diff --git a/login.php b/login.php
index e0fe762645f6bc9e1c92ec24fcb03ef1221621cb..da849bd9e8a90d03ce6526df6046fda36bd7411c 100644
--- a/login.php
+++ b/login.php
@@ -38,6 +38,11 @@ if ($_POST && isset($_POST['luser'])) {
             $_POST['lpasswd'], $errors))) {
         if ($user instanceof ClientCreateRequest) {
             if ($cfg && $cfg->isClientRegistrationEnabled()) {
+                // Attempt to automatically register
+                if ($user->attemptAutoRegister())
+                    Http::redirect('tickets.php');
+
+                // Auto-registration failed. Show the user the info we have
                 $inc = 'register.inc.php';
                 $user_form = UserForm::getUserForm()->getForm($user->getInfo());
             }
@@ -87,23 +92,7 @@ elseif ($user = UserAuthenticationBackend::processSignOn($errors, false)) {
     elseif ($user instanceof ClientCreateRequest) {
         if ($cfg && $cfg->isClientRegistrationEnabled()) {
             // Attempt to automatically register
-            $user_form = UserForm::getUserForm()->getForm($user->getInfo());
-            $bk = $user->getBackend();
-            $defaults = array(
-                'timezone_id' => $cfg->getDefaultTimezoneId(),
-                'dst' => $cfg->observeDaylightSaving(),
-                'username' => $user->getUsername(),
-            );
-            if ($bk->supportsInteractiveAuthentication())
-                $defaults['backend'] = $bk::$id;
-            if ($user_form->isValid(function($f) { return !$f->get('private'); })
-                    && ($U = User::fromVars($user_form->getClean()))
-                    && ($acct = ClientAccount::createForUser($U, $defaults))
-                    // Confirm and save the account
-                    && $acct->confirm()
-                    // Login, since `tickets.php` will not attempt SSO
-                    && ($cl = new ClientSession(new EndUser($U)))
-                    && ($bk->login($cl, $bk)))
+            if ($user->attemptAutoRegister())
                 Http::redirect('tickets.php');
 
             // Unable to auto-register. Fill in what we have and let the