Authentication with DB and LDAP
Posted: Mon Apr 06, 2009 3:51 am
Code: Select all
function auth_does_password_match(&$user,$cleartext_password)
{
$authCfg = config_get('authentication');
$ret = new stdClass();
$ret->status_ok = true;
$ret->msg = 'ok';
if ('LDAP' == $authCfg['method'])
{
$msg[ERROR_LDAP_AUTH_FAILED] = lang_get('error_ldap_auth_failed');
$msg[ERROR_LDAP_SERVER_CONNECT_FAILED] = lang_get('error_ldap_server_connect_failed');
$msg[ERROR_LDAP_UPDATE_FAILED] = lang_get('error_ldap_update_failed');
$msg[ERROR_LDAP_USER_NOT_FOUND] = lang_get('error_ldap_user_not_found');
$msg[ERROR_LDAP_BIND_FAILED] = lang_get('error_ldap_bind_failed');
$xx = ldap_authenticate($user->login, $cleartext_password);
$ret->status_ok = $xx->status_ok;
$ret->msg = $msg[$xx->status_code];
if ($xx->status_ok)
{
if ($user->comparePassword($cleartext_password) == tl::OK) $ret->status_ok = true;
}
}
else // normal database password compare
{
if ($user->comparePassword($cleartext_password) != tl::OK)
$ret->status_ok = false;
}
return $ret;
}
I like to have two authentication methods (DB and LDAP). If LDAP fails, Testlink shall check with DB. If DB authentication is ok, the authentication should pass.