Mit den LDAP Funktionen von PHP kann man wie folgt recht einfach Benutzer gegen ein Active Directory authentifizieren (LDAP_SERVER ist durch die Adresse des AD-Servers zu ersetzen):
-
/**
-
* Authenticates a user against Active Directory.
-
*
-
* @param string The user's Windows username.
-
* @param string The user's Windows password.
-
* @return bool Whether the user could be authenticated.
-
*/
-
public function Authenticate($username, $password)
-
{
-
$ds = ldap_connect(LDAP_SERVER);
-
if ($ds)
-
{
-
$authenticated = false;
-
$bind = ldap_bind($ds, $username, $password);
-
if ($bind)
-
{
-
$authenticated = true;
-
}
-
ldap_close($ds);
-
return $authenticated;
-
}
-
else
-
{
-
$err = 'Verbindung zum LDAP-Server nicht möglich: ' . LDAP_SERVER;
-
throw new Exception($err);
-
}
-
}











