note 17932 deleted from function.ldap-bind by nicos

From: Date: Fri, 20 Sep 2002 14:47:43 +0000
Subject: note 17932 deleted from function.ldap-bind by nicos
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-37048@lists.php.net to get a copy of this message
It took quite a while to figure out how to do LDAP authentication as there wasn't a complete example ... just some cryptic notes about passwords. So, here's what I came up with that works for me: // $inp_uid contains the user id to be authenticated // $inp_passwd contains the plain text password to be authenticated $ds=ldap_connect("ldap.someserver.com"); //substitute the real host name in the previous statement if ($ds) { $r=@ldap_bind($ds); // this is an anonymous bind $st_search="uid=$res_uid"; // need to set the right root search information in next statement. // Your requirement may be different $sr=ldap_search($ds,"ou=mycompany.com,o=My Company", "$st_search"); $info = ldap_get_entries($ds, $sr); for ($i=0; $i<$info["count"]; $i++) { $dn=$info[$i]["dn"]; } // I now know the dn needed to authenticate // now bind to see if the uid and password work // the password is still plain text $r=@ldap_bind($ds, $dn, $inp_passwd); if ($r) { $str_passok="Yes"; // ldap_bind will return TRUE if everything matches } else { $str_passok="No"; // otherwise ldap_bind will return FALSE } ldap_close($ds); } else { $error_string="Error -- unable to connect to ldap.someserver.com"; } I'm sure that there's more error checking that needs to be done, but this provides the basic skeleton....

« previous php.notes (#37048) next »