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);
Member
20 Points
208 Posts
LDAP/ADAM - set password error after user creation
Aug 03, 2009 01:52 PM|avikumar|LINK
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();
}
Participant
1133 Points
610 Posts
Re: LDAP/ADAM - set password error after user creation
Aug 04, 2009 02:29 PM|raghu1|LINK
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();