diff --git a/simplesamlphp_auth.module b/simplesamlphp_auth.module
index 5c5f200..cf5df36 100644
--- a/simplesamlphp_auth.module
+++ b/simplesamlphp_auth.module
@@ -366,44 +366,46 @@ function simplesamlphp_auth_user_insert(&$edit, $account, $category = NULL) {
   if ($category = 'account') {
     // If user registration has a valid session...
     if ($_simplesamlphp_auth_as->isAuthenticated()) {
-      // Get name from default attributes.
-      try {
-        _simplesaml_auth_debug(t('Registering user [%acctname]', array('%acctname' => $account->name)));
-        $account->name = _simplesamlphp_auth_get_default_name($account->uid);
-      }
-      catch (Exception $e) {
-        drupal_set_message(t('Your user name was not provided by your identity provider (IDP).'), "error");
-        watchdog('simplesamlphp_auth', $e->getMessage(), NULL, WATCHDOG_CRITICAL);
-      }
-
-      db_update('users')
-        ->fields(array('name' => $account->name))
-        ->condition('uid', $account->uid)
-        ->execute();
-
-      _simplesaml_auth_debug(t('Updating username [%acctname]', array('%acctname' => $account->name)));
-
-      // Get mail from default attribute.
-      try {
-        $mail_address = _simplesamlphp_auth_get_mail();
-      }
-      catch (Exception $e)  {
-        drupal_set_message(t('Your e-mail address was not provided by your identity provider (IDP).'), "error");
-        watchdog('simplesamlphp_auth', $e->getMessage(), NULL, WATCHDOG_CRITICAL);
-      }
+      if (_simplesamlphp_auth_get_authname() == $account) {
+        // Get name from default attributes.
+        try {
+          _simplesaml_auth_debug(t('Registering user [%acctname]', array('%acctname' => $account->name)));
+          $account->name = _simplesamlphp_auth_get_default_name($account->uid);
+        }
+        catch (Exception $e) {
+          drupal_set_message(t('Your user name was not provided by your identity provider (IDP).'), "error");
+          watchdog('simplesamlphp_auth', $e->getMessage(), NULL, WATCHDOG_CRITICAL);
+        }
 
-      if (!empty($mail_address)) {
         db_update('users')
-          ->fields(array('mail' => $mail_address))
+          ->fields(array('name' => $account->name))
           ->condition('uid', $account->uid)
           ->execute();
+
+        _simplesaml_auth_debug(t('Updating username [%acctname]', array('%acctname' => $account->name)));
+
+        // Get mail from default attribute.
+        try {
+          $mail_address = _simplesamlphp_auth_get_mail();
+        }
+        catch (Exception $e)  {
+          drupal_set_message(t('Your e-mail address was not provided by your identity provider (IDP).'), "error");
+          watchdog('simplesamlphp_auth', $e->getMessage(), NULL, WATCHDOG_CRITICAL);
+        }
+
+        if (!empty($mail_address)) {
+          db_update('users')
+            ->fields(array('mail' => $mail_address))
+            ->condition('uid', $account->uid)
+            ->execute();
+        }
+
+        _simplesaml_auth_debug(t('Updating mail [%mailaddr]', array('%mailaddr' => $mail_address)));
       }
       
       if (module_exists('rules')) {
         rules_invoke_event('simplesamlphp_auth_rules_event_register', $account); 
       }
-
-      _simplesaml_auth_debug(t('Updating mail [%mailaddr]', array('%mailaddr' => $mail_address)));
     }
   }
 }
