I am learning how to perform CRUD operations on a LDAP directory and using ApacheDS for the purpose.I am trying to add a new user but keep getting the following warning:
Warning: ldap_add(): Add: Constraint violation
Here's the php code I am using:
<?php
function ldap_add_user($user)
{
include('ldap_config.php');
include('ldap_admin.php');
$connect = ldap_connect($host, $port);
if ($connect)
{
ldap_set_option($connect, LDAP_OPT_PROTOCOL_VERSION, 3);
$bind = ldap_bind($connect,$username,$password);
$info['uid'] = $user['mail_id'];
$info['userPassword'] = $user['password'];
$info['cn'] = $user['firstname'].' '.$user['lastname'];
$info['sn'] = $user['lastname'];
$info['objectClass'][3] = "inetOrgPerson";
$info['objectClass'][2] = "organizationalPerson";
$info['objectClass'][1] = "person";
$info['objectClass'][0] = "top";
$dn="uid=".$user['mail_id'].", ou=auth_users, o=mycompany";
$r = ldap_add($connect,$dn,$info);
ldap_close($connect);
return true;
}
else
{
return false;
}
}
?>
And,the interesting thing is that the above code works just fine when I use a numeric password for the $user['password'], but when I pass alphanumeric or non-numeric passwords I get the warning mentioned above.