0
// User Custom Validate event
function User_CustomValidate(&$usr, &$pwd) {
// Enter your custom code to validate user, return TRUE if valid.     


// LDAP authentication example for User_CustomValidate server event
if (!function_exists("ldap_connect"))
    die("LDAP extension not installed.");
$ldapconn = ldap_connect("server.company.com", 389) or die("Could not connect to LDAP server."); // Note: Replace the host name and port
if ($ldapconn && ldap_bind($ldapconn, $usr, $pwd)) {
    $this->setCurrentUserName($usr); // Set the current user name    
    return TRUE;
}

return FALSE;

}

I have an application that uses this block of code to facilitate LDAP authentication. On the login page, users must put in company\user.name - How can I concatenate the "company\" part to the usr variable in this code?

4

1 回答 1

0

您所要做的就是在用户名中包含“公司”部分。您可以将 validate 调用包含在公司域中:User_CustomValidate('username', 'password', 'company');或在函数中设置默认值以$domain自行处理:function User_CustomValidate(&$usr, &$pwd, $domain = 'company') {

这应该可以解决问题:

// User Custom Validate event
function User_CustomValidate(&$usr, &$pwd, $domain = '') {
    // Enter your custom code to validate user, return TRUE if valid.     

    //Add the slashes to domain if necessary
    $domain = (!empty($domain))?$domain.'\\':'';

    // LDAP authentication example for User_CustomValidate server event
    if (!function_exists("ldap_connect"))
        die("LDAP extension not installed.");
    $ldapconn = ldap_connect("server.company.com", 389) or die("Could not connect to LDAP server."); // Note: Replace the host name and port
    if ($ldapconn && ldap_bind($ldapconn, $domain.$usr, $pwd)) {
        $this->setCurrentUserName($usr); // Set the current user name    
        return TRUE;
    }

    return FALSE;
}
于 2013-06-07T18:50:32.583 回答