Hi,
I wonder if anyone could help me…..
Assigning default password
I’ve written the following codes to add a new user in our Active Directory. It adds the user no problem. But no matter what I do with the userpassword / unicodepwd attribute, the user still have a blank password by default. We need to have “password” as the default password.
I’ve tried setting the “userPassword” and “unicodepwd” attributes (in 3 separate tests) – see the three lines below, and it was still giving a blank default password!
$user['userPassword'] = 'password';
$user['userPassword'] = '{MD5}'.base64_encode(pack('H*',md5('password')));
$user["unicodepwd"] = "{md5}".base64_encode(pack("H*",md5("password")));
MS Exchange mailbox
I would also like to setup the new user’s MS Exchange mailbox in php at the same time. I’ve attempted the following but it just generate error if I uncomment the line below.
$user["showInAddressBook"][0] = "CN=Default Global Address List,CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=CK College,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=CK,DC=lan; CN=All Users,CN=All Address Lists,CN=Address Lists Container,CN=CK College,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=CK,DC=lan; CN=All Students,CN=All Address Lists,CN=Address Lists Container,CN=CK College,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=CK,DC=lan";
Below is the function I’ve written to add an AD user Peter Pan.
Any idea/suggestions would be very much appreciated. J
function ldap_adduser()
{
// ****************
// Add new AD user
// ****************
$ldapconn = ldap_start();
$user["givenname"] = "Peter Alan";
$user["sn"] = "Pan";
$user["displayname"] = "Peter Pan";
$user["distinguishedname"] = "CN=PPan,OU=CKTest,DC=CK,DC=lan";
$user["homedirectory"] = '\\\sal\home$\%username%';
$user["homedrive"] = "h:";
$user["samaccountname"] = "PPan";
$user["profilepath"] = '\\\sal\profiles$\mandatory';
$user["objectcategory"] = "CN=Person,CN=Schema,CN=Configuration,DC=CK,DC=lan";
$user['cn'] = "PPan";
$user["userprincipalname"] = $user["samaccountname"]."@DOMAIN";
$user['objectclass'][0] = "top";
$user['objectclass'][1] = "person";
$user['objectclass'][2] = "organizationalPerson";
$user['objectclass'][3] = "user";
$user['mail'] = "ppan@DOMAIN";
// $user['userPassword'] = '{MD5}'.base64_encode(pack('H*',md5('password')));
// $user["unicodepwd"] = "{md5}".base64_encode(pack("H*",md5("password")));
$user["userAccountControl"] = "544";
//$user["showInAddressBook"][0] = "CN=Default Global Address List,CN=Default Global Address List,CN=All Global Address Lists,CN=Address Lists Container,CN=CK College,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=CK,DC=lan; CN=All Users,CN=All Address Lists,CN=Address Lists Container,CN=CK College,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=CK,DC=lan; CN=All Students,CN=All Address Lists,CN=Address Lists Container,CN=CK College,CN=Microsoft Exchange,CN=Services,CN=Configuration,DC=CK,DC=lan";
print_r($user);
$dn = "CN=PPan,OU=CKTest,DC=CK,DC=lan";
$result = ldap_add($ldapconn, $dn, $user);
//assign user to AllStudents group
$group_name = "CN=AllStudents,OU=Groups,OU=Students,DC=CK,DC=lan";
$group_info['member'] = $dn; // User's DN is added to group's 'member' array
ldap_mod_add($ldapconn,$group_name,$group_info);
if ($result)
{
echo "User added!";
}
else
{ echo "There was a problem!";}
ldap_end($ldapconn);
}
ldap_add() - cannot assign default password/MS Exchange mail
Moderator: General Moderators
-
constance.kan
- Forum Newbie
- Posts: 2
- Joined: Tue Feb 26, 2008 4:00 am