locked
LDAP/ADAM - set password error after user creation RRS feed

  • Question

  • User238037111 posted

    Hello

    I am using following code for new user creation and thensetting password for new user. User are creating succesfully, but at the time of setting password it is giving following error, Please let me know whats wrong I am doing gere

      A constraint violation occurred. (Exception from HRESULT: 0x8007202F)

    ------------------

    DirectoryEntry parent = new DirectoryEntry(
    "LDAP://portal:389/OU=Portal Users,OU=PortalADAM,O=Portal,C=US",null, null, AuthenticationTypes.Secure);

    DirectoryEntry userAdd = parent.Children.Add(sUserName.ToString().Trim(), "user");

                using (userAdd)
                {

                    //user.Properties["msDS-UserAccountDisabled"].Value = false;
                    userAdd.Properties["displayName"].Value = sFirstName + " " + sLastName;
                    userAdd.Properties["givenName"].Value = sFirstName;
                    userAdd.Properties["sn"].Value = sLastName;
                    userAdd.Properties["mail"].Value = sEmail;
                    userAdd.Properties["userPrincipalName"].Value = tbAddUserName.Text;
                    userAdd.CommitChanges();

                    DirectoryEntry newUserEntry = new DirectoryEntry(userAdd.Path, "administrator", "password@123", AuthenticationTypes.ServerBind);
                    newUserEntry.RefreshCache();
                    string password1 = "password123";
                    newUserEntry.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_PORTNUMBER, 389 });
                    newUserEntry.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_METHOD, ADS_PASSWORD_ENCODE_CLEAR });
                    newUserEntry.Invoke("SetPassword", new object[] { password1.ToString() });
                    newUserEntry.CommitChanges();
                }

    Monday, August 3, 2009 1:52 PM

All replies

  • User-2009597737 posted

    Your password set looks pretty complicated: out of curiosity: why are you doing a refreshCache. Purpose :

    NewUserEntry.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_PORTNUMBER, 389 });
                    newUserEntry.Invoke("SetOption", new object[] { ADS_OPTION_PASSWORD_METHOD, ADS_PASSWORD_ENCODE_CLEAR });

    The folowing simple code should be fine:


    newUserEntry.AuthenticationType=AuthenticationTypes.Secure; // shoule be enough

    object[] passWord= new object[] {passworrd1}

    object[] retrunStat = newUSerEntry.Invoke("SetPassword", passWord);

    newUSerEntry.commitChnages();




    Tuesday, August 4, 2009 2:29 PM