--- authentication_api.php.orig	Fri Oct 19 09:54:58 2007
+++ authentication_api.php	Thu Nov  1 23:55:48 2007
@@ -82,9 +82,15 @@
 		$t_login_method = config_get( 'login_method' );
 
 		if ( false === $t_user_id ) {
-			if ( BASIC_AUTH == $t_login_method ) {
-				# attempt to create the user if using BASIC_AUTH
-				$t_cookie_string = user_create( $p_username, $p_password );
+			if ( BASIC_AUTH == $t_login_method || LDAP == $t_login_method ) {
+				
+			  # attempt to create the user if using BASIC_AUTH or LDAP
+			  if ( BASIC_AUTH == $t_login_method) {
+				    $t_cookie_string = user_create( $p_username, $p_password );
+				} elseif ( LDAP == $t_login_method ) {
+					# get the users' email address as well if using LDAP
+					$t_cookie_string = user_create( $p_username, '', ldap_email_from_username( $p_username ), null, false, true, ldap_realname_from_username( $p_username ) );
+				}
 
 				if ( false === $t_cookie_string ) {
 					# it didn't work
@@ -136,6 +142,11 @@
 
 		user_reset_failed_login_count_to_zero( $t_user_id );
 		user_reset_lost_password_in_progress_count_to_zero( $t_user_id );
+		
+		# set user Real Name to value from LDAP
+		if ( ON == config_get( 'use_ldap_realname' ) ) {
+		  user_set_realname( $t_user_id, ldap_realname_from_username( $p_username ) );
+		}
 
 		# set the cookies
 		auth_set_cookies( $t_user_id, $p_perm_login );
