I worked on it last night and i discovered something wrong within your function, in fact when you have used OR it makes the function too costly for Mysql.. here's what i've discovered
if i use
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation, smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM mos_users jos
RIGHT JOIN smf_members smf ON jos.username = smf.memberName
WHERE jos.username = 'test_functions_smf'
OR smf.memberName = 'test_functions_smf'
LIMIT 1
i will get the results
name username email registerDate block password activation memberName realName passwd emailAddress dateRegistered is_activated validation_code
test_functions_smf test_functions_smf test_functions_smf@siemens-mobiles.org 2005-10-11 08:08:04 0 ae2b1fca515949e5d54fb22b8ed95575 test_functions_smf test_functions_smf 28b4bb3f81f3c6682fc4f77c0a52091dcb82f17e test_functions_smf@siemens-mobiles.org 1129010884 1
and in "explain sql" i will have:
table type possible_keys key key_len ref rows Extra
smf ALL memberName NULL NULL NULL 7187
jos ALL NULL NULL NULL NULL 7189 Using where
But if i use
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation,
smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM mos_users jos
RIGHT JOIN smf_members smf ON jos.username = smf.memberName
WHERE smf.memberName = 'test_functions_smf'
LIMIT 1
i will get the results
name username email registerDate block password activation memberName realName passwd emailAddress dateRegistered is_activated validation_code
test_functions_smf test_functions_smf test_functions_smf@siemens-mobiles.org 2005-10-11 08:08:04 0 ae2b1fca515949e5d54fb22b8ed95575 test_functions_smf test_functions_smf 28b4bb3f81f3c6682fc4f77c0a52091dcb82f17e test_functions_smf@siemens-mobiles.org 1129010884 1
but i'll have in explain sql
table type possible_keys key key_len ref rows Extra
smf ref memberName memberName 30 const 3 Using where
jos ALL NULL NULL NULL NULL 7189
So as you can see, not using OR will invoke much less rows to compare because your one is comparing 7000+ rows together and it takes much time, but this one will compare 7000+ to 3 rows which is much much less...
anyway my function looks like this now:
function isValidUser(&$row, $username, $password) {
global $database, $smf_prefix;
//try first with MOS
$sql = "
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation,
smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM #__users jos
LEFT JOIN {$smf_prefix}members smf ON jos.username = smf.memberName
WHERE jos.username = '$username'
LIMIT 1
";
$database->setQuery($sql);
$database->loadObject( $row );
if ($row != null) {
$mos = ($row->password == md5($password));
$smf = ($row->passwd == sha1(strtolower($username) . $password));
if (!$mos && !$smf)
return 0;
if ($mos && $smf) {
if (!$row->block && $row->is_activated) return 1;
if ($row->block && !$row->is_activated) return 4;
return 5;
}
if ($mos)
return 2;
if ($smf)
return 3;
}
//try with SMF
$sql = "
SELECT jos.name, jos.username, jos.email, jos.registerDate, jos.block, jos.password, jos.activation,
smf.memberName, smf.realName, smf.passwd, smf.emailAddress, smf.dateRegistered, smf.is_activated, smf.validation_code
FROM #__users jos
RIGHT JOIN {$smf_prefix}members smf ON jos.username = smf.memberName
WHERE smf.memberName = '$username'
LIMIT 1
";
$database->setQuery($sql);
$database->loadObject( $row );
if ($row != null) {
$mos = ($row->password == md5($password));
$smf = ($row->passwd == sha1(strtolower($username) . $password));
if (!$mos && !$smf)
return 0;
if ($mos && $smf) {
if (!$row->block && $row->is_activated) return 1;
if ($row->block && !$row->is_activated) return 4;
return 5;
}
if ($mos)
return 2;
if ($smf)
return 3;
}
}
I confirm that it's much much better to use it this way, but i want you to confirm that it does the exact same work as yours so my function will be good to use it
Best Regards,
Gandalf