Topic: [Request] Use email address to login rather than username

I would like to have my users enter their email address and password in order to login. I still want to allow them to have/create a username at sign-up. But because people change their email addresses so frequently, and often forget to update it everywhere, my info quickly goes stale.

I have searched here and punres.org and did not find it. But that does not mean it hasn't been asked, and done, before.

Re: [Request] Use email address to login rather than username

This is quite easy smile

Ok, open login.php

Find this line:

$form_username     = trim($_POST['req_username']);

Replace with

$form_email        = trim($_POST['req_email']);

Then, find this line:

$username_sql     = ($db_type == 'mysql' || $db_type == 'mysqli') ? 'username=\''.$db->escape($form_username).'\'' : 'LOWER(username)=LOWER(\''.$db->escape($form_username).'\')';

Replace with:

$email_sql         = ($db_type == 'mysql' || $db_type == 'mysqli') ? 'email=\''.$db->escape($form_email).'\'' : 'LOWER(email)=LOWER(\''.$db->escape($form_email).'\')';

After that, find:

$result = $db->query('SELECT id, group_id, password, save_pass FROM '.$db->prefix.'users WHERE '.$username_sql) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());

Replace with:

$result = $db->query('SELECT id, group_id, password, save_pass FROM '.$db->prefix.'users WHERE '.$email_sql) or error('Unable to fetch user info', __FILE__, __LINE__, $db->error());

Find:

$required_fields = array('req_username' => $lang_common['Username'], 'req_password' => $lang_common['Password']);

Replace with:

$required_fields = array('req_email' => $lang_common['E-mail'], 'req_password' => $lang_common['Password']);

Find:

<label class="conl"><strong><?php echo $lang_common['Username'] ?></strong><br /><input type="text" name="req_username" size="25" maxlength="25" tabindex="1" /><br /></label>

Replace with:

<label class="conl"><strong><?php echo $lang_common['E-mail'] ?></strong><br /><input type="text" name="req_email" size="25" maxlength="25" tabindex="1" /><br /></label>

This should do it smile Have fun smile

Re: [Request] Use email address to login rather than username

THANKS, elbekko, for the code and for the clarity of your instructions!

Re: [Request] Use email address to login rather than username

No problem, it's just a small modification smile

Re: [Request] Use email address to login rather than username

does this replace the username displayed also?

~James
FluxBB - Less is more

Re: [Request] Use email address to login rather than username

Only the login part smile

Re: [Request] Use email address to login rather than username

btw, elbekko this is a great thing to put on the PunRes wiki, http://punres.org/doku.php for people to find in the future smile

Re: [Request] Use email address to login rather than username

Ok, I'll put it on soonish smile

Re: [Request] Use email address to login rather than username

On the wiki. But I don't really get the syntax of the DokuWiki tho sad