AUTH with LDAP problems
| From: | Erik Lemcke | Date: | Fri, 04 May 2007 14:04:36 +0000 |
| Subject: | AUTH with LDAP problems | ||
| Groups: | php.pear.general | ||
| Request: | Send a blank email to pear-general+get-27208@lists.php.net to get a copy of this message | ||
Hi,
For a system I'm building I would like to use the PEAR AUTH package to authenticate users
against a Novell directory server.
Since I didn't know anything about LDAP, I first created this PHP script for testing:
<?php
if ($HTTP_POST_VARS[trylogin])
{
$ldapserver = 'ldap_servername';
$ldaprdn = "cn=" . $HTTP_POST_VARS[username] .
",ou=Org_location,o=org_name";
$ldappass = $HTTP_POST_VARS[password];
$ldapconn = ldap_connect($ldapserver);
$ldapbind = ldap_bind($ldapconn,$ldaprdn,$ldappass);
if ($ldapbind) {echo "login succesfull";}
else { echo "login failed"; }
}
echo "<form method='post' action='$PHP_SELF'>";
?>
<h4 class='sidebar'>Sign in / Info</h4>
<small><b>User Name:</b></small><br>
<input type=text name='username' size=20 maxlength=254><br>
<small><b>Password:</b></small><br>
<input type=password name='password' size=20 maxlength=254><br>
<input type='Submit' border='0' name='trylogin'
value='Login'>
</form>
That test script worked great, so I thought it would be easy to build the same thing with PEAR:AUTH
This is what I created:
<?php
require_once "Auth/Auth.php";
function loginFunction(){
echo "<form method=\"post\" action=\"" .
$_SERVER['PHP_SELF'] . "\">";
echo "user<input type=\"text\" name=\"username\"><br
/>";
echo "pass<input type=\"password\" name=\"password\"><br
/>";
echo "<input type=\"submit\">";
echo "</form>";
}
$params = array(
"host" => "ldap_servername",
"port" => "389",
"basedn" => "ou=org_location,o=org_name",
"userdn" => "cn",
"binddn" => $HTTP_POST_VARS[username] ,
"bindpw" => $HTTP_POST_VARS[password] ,
"debug" => true
);
$a = new Auth("LDAP", $params, "loginFunction");
$a->start();
if ($a->getAuth()) {
echo "<br/><b>User authenticated!</b>";
} else {
echo "<br/><b>User not authenticated!</b>";
}
?>
The problem is that whatever I do, I only get the script to say "User not authenticated!",
so I think I did something wrong creating this script, I can't however find out what's
wrong.
Any idea's?
Regards,
Erik
This message has been scanned for malware by SurfControl plc. www.surfcontrol.com