diff --git a/modules/multiauth/lib/Auth/Source/MultiAuth.php b/modules/multiauth/lib/Auth/Source/MultiAuth.php
index d613564493e95ac6adbd56de664bfb12593af3e3..737eb28a1dea1c97888812f9b864660ea040b41a 100644
--- a/modules/multiauth/lib/Auth/Source/MultiAuth.php
+++ b/modules/multiauth/lib/Auth/Source/MultiAuth.php
@@ -186,6 +186,44 @@ class sspmod_multiauth_Auth_Source_MultiAuth extends SimpleSAML_Auth_Source {
 		$source->logout($state);
 	}
 
+	/**
+	* Set the previous authentication source.
+	*
+	* This method remembers the authentication source that the user selected
+	* by storing its name in a cookie.
+	*
+	* @param string $source Name of the authentication source the user selected.
+	*/
+	public function setPreviousSource($source) {
+		assert('is_string($source)');
+
+		$cookieName = 'multiauth_source_' . $this->authId;
+
+		/* We save the cookies for 90 days. */
+		$saveUntil = time() + 60*60*24*90;
+
+		/* The base path for cookies. 
+		This should be the installation directory for simpleSAMLphp. */
+		$config = SimpleSAML_Configuration::getInstance();
+		$cookiePath = '/' . $config->getBaseUrl();
+
+		setcookie($cookieName, $source, $saveUntil, $cookiePath);
+	}
+
+	/**
+	* Get the previous authentication source.
+	*
+	* This method retrieves the authentication source that the user selected
+	* last time or NULL if this is the first time or remembering is disabled.
+	*/
+	public function getPreviousSource() {
+		$cookieName = 'multiauth_source_' . $this->authId;
+		if(array_key_exists($cookieName, $_COOKIE)) {
+			return $_COOKIE[$cookieName];
+		} else {
+			return NULL;
+		}
+	}
 }
 
 ?>
diff --git a/modules/multiauth/templates/selectsource.php b/modules/multiauth/templates/selectsource.php
index 135a43a2f1c180d95dd381d6f9b97eb10ee0e4fe..39a09c72b4f88b796160663ad81296de469245a7 100644
--- a/modules/multiauth/templates/selectsource.php
+++ b/modules/multiauth/templates/selectsource.php
@@ -8,15 +8,25 @@ $this->includeAtTemplateBase('includes/header.php');
 
 <p><?php echo $this->t('{multiauth:multiauth:select_source_text}'); ?></p>
 
+<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="get">
+<input type="hidden" name="AuthState" value="<?php echo htmlspecialchars($this->data['authstate']); ?>" />
 <ul>
 <?php
 foreach($this->data['sources'] as $source) {
-	echo '<li class="' . htmlspecialchars($source['css_class']) . ' authsource">' .
-		'<a href="?source=' . htmlspecialchars($source['source']) .
-		'&AuthState=' . htmlspecialchars($this->data['authstate']) . '">' .
-		'<span>' . htmlspecialchars($this->t($source['text'])) . '</span></a></li>';
+	echo '<li class="' . htmlspecialchars($source['css_class']) . ' authsource">';
+	if ($source['source'] === $this->data['preferred']) {
+		$autofocus = ' autofocus="autofocus"';
+	} else {
+		$autofocus = '';
+	}
+	echo '<button type="submit" name="source"' . $autofocus . ' ' .
+		'id="button-' . htmlspecialchars($source['source']) . '" ' .
+		'value="' . htmlspecialchars($source['source']) . '">';
+	echo htmlspecialchars($this->t($source['text']));
+	echo '</button>';
+	echo '</li>';
 }
 ?>
 </ul>
-
+</form>
 <?php $this->includeAtTemplateBase('includes/footer.php'); ?>
diff --git a/modules/multiauth/www/selectsource.php b/modules/multiauth/www/selectsource.php
index 2602f6f16fbe0a328c9719f2840dbaf845446ab0..0f19cff3e67c3514ad2e004bb9e12ebcf5321407 100644
--- a/modules/multiauth/www/selectsource.php
+++ b/modules/multiauth/www/selectsource.php
@@ -19,8 +19,18 @@ $authStateId = $_REQUEST['AuthState'];
 /* Retrieve the authentication state. */
 $state = SimpleSAML_Auth_State::loadState($authStateId, sspmod_multiauth_Auth_Source_MultiAuth::STAGEID);
 
+if (array_key_exists("SimpleSAML_Auth_Default.id", $state)) {
+	$authId = $state["SimpleSAML_Auth_Default.id"];
+	$as = SimpleSAML_Auth_Source::getById($authId);
+} else {
+	$as = NULL;
+}
+
 if (array_key_exists('source', $_REQUEST)) {
 	$source = $_REQUEST['source'];
+	if ($as !== NULL) {
+		$as->setPreviousSource($source);
+	}
 	sspmod_multiauth_Auth_Source_MultiAuth::delegateAuthentication($source, $state);
 } elseif (array_key_exists('multiauth:preselect', $state)) {
 	$source = $state['multiauth:preselect'];
@@ -31,6 +41,11 @@ $globalConfig = SimpleSAML_Configuration::getInstance();
 $t = new SimpleSAML_XHTML_Template($globalConfig, 'multiauth:selectsource.php');
 $t->data['authstate'] = $authStateId;
 $t->data['sources'] = $state[sspmod_multiauth_Auth_Source_MultiAuth::SOURCESID];
+if ($as !== NULL) {
+	$t->data['preferred'] = $as->getPreviousSource();
+} else {
+	$t->data['preferred'] = NULL;
+}
 $t->show();
 exit();