Index: ldap_integration/ldapauth.module
===================================================================
--- ldap_integration/ldapauth.module	(revision 294346)
+++ ldap_integration/ldapauth.module	(working copy)
@@ -262,10 +262,10 @@
     if ($ldap_user = _ldapauth_user_lookup($name)) {
       // Generate a random drupal password. LDAP password will be used anyways.
       $pass = user_password(20);
-
+    
       // If mail attribute is missing, set the name as mail.
       $init = $mail = key_exists(($_ldapauth_ldap->getOption('mail_attr') ? $_ldapauth_ldap->getOption('mail_attr') : LDAPAUTH_DEFAULT_MAIL_ATTR), $ldap_user) ? $ldap_user[$_ldapauth_ldap->getOption('mail_attr')][0] : $name;
-
+    
       $userinfo = array('name' => $name, 'pass' => $pass, 'mail' => $mail, 'init' => $init, 'status' => 1, 'authname_ldapauth' => $name, 'ldap_authentified' => TRUE, 'ldap_dn' => $ldap_user['dn'], 'ldap_config' => $_ldapauth_ldap->getOption('sid'));
       $user = user_save('', $userinfo);
       watchdog('ldapauth', 'New external user %name created from the LDAP server %server.', array('%name' => $name, '%server' => $_ldapauth_ldap->getOption('name')), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
@@ -309,7 +309,7 @@
  * @return
  *  User's LDAP dn success, FALSE otherwise.
  */
-function _ldapauth_auth($name, $pass) {
+function _ldapauth_auth($name, $pass, $create_account = FALSE) {
   global $_ldapauth_ldap;
 
   // Don't allow empty passwords because they cause problems on some setups.
@@ -341,6 +341,18 @@
     if (function_exists('ldapauth_user_filter') && !call_user_func('ldapauth_user_filter', $_ldapauth_ldap->retrieveAttributes($dn)))
       continue;
 
+    // Register this new user.
+    if ($create_account && $ldap_user = _ldapauth_user_lookup($name)) {
+      // Generate a random drupal password. LDAP password will be used anyways.
+      $pass = user_password(20);
+    
+      // If mail attribute is missing, set the name as mail.
+      $init = $mail = key_exists(($_ldapauth_ldap->getOption('mail_attr') ? $_ldapauth_ldap->getOption('mail_attr') : LDAPAUTH_DEFAULT_MAIL_ATTR), $ldap_user) ? $ldap_user[$_ldapauth_ldap->getOption('mail_attr')][0] : $name;
+    
+      $userinfo = array('name' => $name, 'pass' => $pass, 'mail' => $mail, 'init' => $init, 'status' => 1, 'authname_ldapauth' => $name, 'ldap_authentified' => TRUE, 'ldap_dn' => $ldap_user['dn'], 'ldap_config' => $_ldapauth_ldap->getOption('sid'));
+      $user = user_save('', $userinfo);
+      watchdog('ldapauth', 'New external user %name created from the LDAP server %server.', array('%name' => $name, '%server' => $_ldapauth_ldap->getOption('name')), WATCHDOG_NOTICE, l(t('edit'), 'user/'. $user->uid .'/edit'));
+    }
     return $dn;
   }
   return FALSE;
Index: securesite/securesite.inc
===================================================================
--- securesite/securesite.inc	(revision 294345)
+++ securesite/securesite.inc	(working copy)
@@ -156,8 +156,17 @@
 function _securesite_plain_auth($edit) {
   $account = user_load(array('name' => $edit['name'], 'status' => 1));
   if (empty($account->uid)) {
-    // Not a registered user. See if we have guest user credentials.
-    _securesite_guest_login($edit);
+    // Not a registered user. 
+    // If we have correct LDAP credentials, register this new user.
+    if (module_exists('ldapauth') && _ldapauth_auth($edit['name'], $edit['pass'], TRUE) !== FALSE) {
+      $account = user_load(array('name' => $edit['name'], 'status' => 1));
+      // System should be setup correctly now, perform log-in.
+      _securesite_user_login($edit, $account);
+    }
+    else {
+      // See if we have guest user credentials.
+      _securesite_guest_login($edit);
+    }
   }
   else {
     if (user_load(array('name' => $edit['name'], 'pass' => $edit['pass'], 'status' => 1)) !== FALSE || module_exists('ldapauth') && _ldapauth_auth($edit['name'], $edit['pass']) !== FALSE) {
