Pulvinar tempor cras amet ac turpis tristique tristique ... (read more)close
Pulvinar tempor cras amet ac turpis tristique tristique ... (read more)close

LukeTaylor.org Blog

Making I.T that little bit easier !

Moodle - Set The Displayed Teacher Name as the ldap "DisplayName"

by in Windows Blog
  • Font size: Larger Smaller
  • Hits: 8735
  • Print

b2ap3_thumbnail_moodle.jpgWhen installing moodle and authenticating with LDAP we had a problem with teachers who logged in it would display there full name ( first + last name from active directory ) .This guide is to allow an administrator set the LDAP authentication when setting up new users to use there active directory display name instead of there first + last name when authenticating.


In our active directory environment we have users set like the following

for e.g.


First name = George

Last name = Winkle

Display Name = GWinkle

User Name = Gwinkle



First name = Sam

Last name = Junior

Display Name = 0987

User Name = 0987

Ideally we wanted it so when a user logged in , it only displayed there Display Name . Unfortunately there isnt a direct option for this , and requires a bit of code modification to the following files so that the profile page does not load up every time a user clicks on anything . We are using Moodle 2.3.* so a lot of the following code changes were already done ! .

Insert a couple of back slashes "//" in front of the comments below if specified

In moodle->user->editlib find and insert // infront

 $mform->addRule('email', $strrequired, 'required', null, 'client'); 

In the file moodle->user->editadvanced_form.php
and insert // infront

 $err['email'] = get_string('invalidemail'); 


 $err['email'] = get_string('emailexists'); 

In the file in user/edit_form.php
and insert // infront

 $errors['email'] = get_string('invalidemail'); 


$errors['email'] = get_string('emailexists'); 


Now goto lib/moodlelib.php and search for

 function user_not_fully_set_up($user) if (isguestuser($user))return false; return (empty($user->firstname) or empty($user->lastname) or empty($user->email) or over_bounce_threshold($user)); 

It may or may not look like the above , now you need to remove the following from the last long line ( The email part may already be removed )

 or empty($user->lastname) or empty($user->email) 

The Above removes the requirements for a last name and email address , Its quite strange as if you leave the code "or empty($user->lastname)" inplace it gives no warning indicator that a lastname is required instead it states the email address is invald which is strange.

This guide is assuming you have setup LDAP authentication and all users can currently login currently , now login to moodle and goto Site Administrator > Plugins > Authentication > Ldap Server .

in the "First Name" Field replace what ever is in this with "displayName"

Now remove anything in the "Surname" field.


Heres a quick picture of what the "displayName" variable can be changed to , so you can choose what information from AD is used .



Rate this blog entry:


  • No comments made yet. Be the first to submit a comment

Leave your comment

Guest Thursday, 21 October 2021