ponedjeljak, 14. ožujka 2011.

PHP: verifying username and password with LDAP

here is a simple example how you can verify username and password with ldap


        $ldaphost = "aai.host.com";
        $ldapport = 389;
        $ldapconfig['basedn'] = 'dc=host,dc=com';

        $ds = ldap_connect($ldaphost, $ldapport)
        or die("Could not connect to $ldaphost");
        if ($ds)
        {
                $username = mysql_real_escape_string($_POST["user"]);
                $upasswd = mysql_real_escape_string($_POST["pass"]);
$dn="uid=".$username.",".$ldapconfig['basedn'];
                $ldapbind = @ldap_bind($ds, $dn, $upasswd);
                if ($ldapbind) {
$ok=true;
echo "Password OK!<br>";
} else {
echo "Password invalid!<br>";
$ok=false;
exit();
}
}


Nema komentara:

Objavi komentar