I can't find if it is possible or not to change the log in system by using the couple (email, password) instead of (username, password).

I think people never remember their usernames when not available as they wanted and so had to add a number at the end of it ...

4 Answers 4


Both the Login Toboggan and Email Registration modules allow your users to use their email when logging in.

  • Mind you that LoginToboggan has a different (not to say problematic) approach of administrator approvals: drupal.org/node/1069414 Nov 20, 2015 at 12:30

The developer has moved a module that meets your need from the sandbox to the project page: https://www.drupal.org/project/login_email

The module exists as 7.x-1.x-dev It works as is...looks like a bit of assistance can turn this into an official release.


In order to allow both username and email: first add validator

function YOURMODULE_form_user_login_alter(&$form, &$form_state, $form_id) {
    $form['#validate'][1] = 'YOURMODULE_form_user_login_replace_email_validate';
    $form['#validate'][2] = 'user_login_authenticate_validate';
    $form['#validate'][3] = 'user_login_final_validate';

then check if looks like email address (contains @, letters before and after @ and at least 1 '.' after @). If it is, than replace email by username:

function YOURMODULE_form_user_login_replace_email_validate(&$form, &$form_state) {

    $name = $form_state['values']['name'];
    if (strpos($name, '@')) {
        $mailParts = explode('@', $name);
        if ((int)count($mailParts) === 2) {
            $extParts = explode('.', $mailParts[1]);
            if (count($extParts) > 1) {
                $query = db_select('users', 'u');
                $query->fields('u', ['uid']);
                $query->fields('u', ['name']);
                $query->fields('u', ['mail']);
                $query->condition('u.mail', $name, '=');
                $result = $query->execute()->fetchAllAssoc('name');

                if (!empty($result)) {
                    $name = array_keys($result)[0];
                    $form_state['values']['name'] = $name;

I had a specific situation when I had to add email-based authentification to working site with a lot of users leaving the "old" authentification working, and I did it in such a way.


Here's how to let a user login with their email address in Drupal 7:

 * Implements hook_form_alter().
function MY_MODULE_form_alter(&$form, $form_state, $form_id) {

  // On the user login form...
  if ($form_id == 'user_login') {
    // OPTIONAL: Change the title on the user name input.
    $form['name']['#title'] = t('E-mail address');

    // OPTIONAL: Clear the descriptions on the user name and pass inputs.
    $form['name']['#description'] = '';
    $form['pass']['#description'] = '';

    // Prepend a custom validation handler.
    array_unshift($form['#validate'], 'MY_MODULE_user_login_form_validate');



 * A custom validation handler for the user login form.
function MY_MODULE_user_login_form_validate(&$form, &$form_state) {

  // If they provided a valid email address for the user name...
  $name = $form_state['values']['name'];
  if (valid_email_address($name)) {
    // If an account exists for the email address...
    $account = user_load_by_mail($name);
    if ($account) {
      // Set the account's user name onto the form state.
      form_set_value($form['name'], $account->name, $form_state);




Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.