The best reason to consider this change is to allow users to modify their username (profile title) at will, without impacting their login procedure. This is how MySpace works. Lots of users expect other communities to behave the same way.
=======modifications======
Test if login form input appears to be an email address
If YES, search for matching email adress in member database.
If NO, search matching username in member database.
Return username from database, rather than from login form
==========================
Replace this code (CB 1.1 approx Line #1403)
[code:1]
if($_PLUGINS->is_errors()) {
$resultError = $_PLUGINS->getErrorMSG();
} else {
$_CB_database->setQuery( "SELECT * "
. "\n FROM #__users u, "
. "\n #__comprofiler ue "
. "\n WHERE u.username='".$username."' AND u.id = ue.id"
);
[/code:1]
with this code:
modified to allow login with username or email address
[code:1]
if($_PLUGINS->is_errors()) {
$resultError = $_PLUGINS->getErrorMSG();
} else {
if(preg_match("/[\w\.\-]+@\w+[\w\.\-]*?\.\w{1,4}/", $username)){ //username=email addr
$_CB_database->setQuery( "SELECT * "
. "\n FROM #__users u, "
. "\n #__comprofiler ue "
. "\n WHERE u.email='".$username."' AND u.id = ue.id"
);
}else{ // no email in username
$_CB_database->setQuery( "SELECT * "
. "\n FROM #__users u, "
. "\n #__comprofiler ue "
. "\n WHERE u.username='".$username."' AND u.id = ue.id"
);
}
[/code:1]
Replace this code (CB 1.1 approx Line #1487)
[code:1]
if ( $hashedPwdLogin ) { // Joomla 1.0.12 and below:
$mainframe->login( $username, cbHashPassword( $passwd2 ) );
} elseif ( checkJversion() == 1 ) { // Joomla 1.5 RC and above:
$mainframe->login( array( 'username' => $username, 'password' => $passwd2 ), array() );
} else {
$mainframe->login( $username, $passwd2 );
}
[/code:1]
with this code
[code:1]
if ( $hashedPwdLogin ) { // Joomla 1.0.12 and below:
$mainframe->login( $row->username, cbHashPassword( $passwd2 ) );
} elseif ( checkJversion() == 1 ) { // Joomla 1.5 RC and above:
$mainframe->login( array( 'username' => $username, 'password' => $passwd2 ), array() );
} else {
$mainframe->login( $row->username, $passwd2 );
}
[/code:1]
====== Issues ==============
If your member changes his username to something that includes a space, he will not be able to enter his modified username for login (at that point only his email address will work properly). I suggest that you change the login error message to something like this...
Did you change your username, or cannot remember it? You can use your email address and password to login, or we can resend your login info by clicking <here>.
The "Forgot password" link requires a valid username and email in order to work. If users are changing their username from time to time, they may easily forget it. Perhaps this form should be changed to exclude username, and work with only the email address. Here is a thread on the subject
www.joomlapolis.com/component/option,com_joomlaboard/Itemid,/func,view/catid,42/id,47447/#47447
Ideally, I would like to see the 'login by email address' feature integrated into CB with admin control options.
Post edited by: bertm, at: 2007/11/20 02:05