For those who have had the same issue and have come in search of a solution, you could follow my method.
Requirement-
Having to enter a unique username in addition to an email address is a pain for a few organizations. So we wanted to remove the username field altogether. The final look would be-
Method-
Theory- Although the restrictions on email addresses are far too less, two thirds of the mail addresses have stringent enough restrictions. Let me explain. The email address Joe@schmo.com is different from joe@schmo.com. If that were the case, moodle would consider them the same user as in the authentication process, moodle converts the username/email address to lowercase string. We are saved from the trouble of handling this as gmail, yahoo, hotmail and the like would give you an error if you try to create joe@schmo.com when Joe@schmo.com exists.
So the hack we did to make the users feel that they are entering just their email address, which in itself is bound to be unique, is to make the username field the email address field. We removed the email address again field and used the email address field as email again. So from the user interface, they enter the email address twice. But from the database perspective, the users enter their username and email address. This hack needs the constraints/restrictions on username, email and email again modified a bit.
Steps- 1. The account creation uses login/signup_form.php. To remove the email again part, comment out this part-
// $mform->addElement('text', 'email2', get_string('emailagain'), 'maxlength="100" size="25"');
// $mform->setType('email2', PARAM_RAW_TRIMMED);
// $mform->addRule('email2', get_string('missingemail'), 'required', null, 'server');
2. To remove the restrictions, comment out from login/signup_form.php-
// $errors['username'] = get_string('usernamelowercase'); ----> This lets username have uppercase letters.
// $errors['email2'] = get_string('missingemail'); ----> This removes the requirement to enter email again.
// $errors['email2'] = get_string('invalidemail'); ----> This removes the restriction of email again being the same as email.
From user/lib.php, comment out-
// throw new moodle_exception('usernamelowercase');
Technically, we are not removing the restrictions. We are just making moodle do nothing if these restrictions occur.
3. To add the restriction that email address (username according to database) is the same as email address again (email according to database), in login/signup_form add the restriction-
if (! validate_email($data['email'])) {
$errors['email'] = get_string('invalidemail');
} else if ($DB->record_exists('user', array('email'=>$data['email']))) {
$errors['email'] = get_string('emailexists').' <a href="forgot_password.php">'.get_string('newpassword').'?</a>';
} else if ($data['email'] != $data['username']) {
$errors['email'] = get_string('invalidemail');