Can not set password when create new Active Directory with C# -
Can not set password when create new Active Directory with C# -
i'm getting stuck creating active directory user c#
this code utilize create new user:
public bool createuser(string username, string password) { seek { directoryentry entry = new directoryentry(ldapconnectionstring, adconnectionusername, adconnectionpassword, authenticationtypes.secure); // utilize add together method add together user organizational unit. directoryentry user = entry.children.add("cn=" + username, "user"); // set samaccountname, commit changes directory. user.properties["samaccountname"].value = username; user.properties["userprincipalname"].value = username + constants.adproperties.adupnlogonsuffix; user.commitchanges(); // set password never expire int non_expire_flag = 0x10000; int val = (int)user.properties["useraccountcontrol"].value; user.properties["useraccountcontrol"].value = val | non_expire_flag; user.commitchanges(); // enable user val = (int)user.properties["useraccountcontrol"].value; user.properties["useraccountcontrol"].value = val & ~(int)constants.ads_user_flag_enum.ads_uf_accountdisable; user.commitchanges(); user.refreshcache(); // set password user.usepropertycache = true; user.invoke("setoption", new object[] { constants.ads_user_flag_enum.ads_option_password_portnumber, constants.adproperties.adport }); user.invoke("setoption", new object[] { constants.ads_user_flag_enum.ads_option_password_method, constants.ads_user_flag_enum.ads_password_encode_clear }); user.properties["lockouttime"].value = 0; user.invoke("setpassword", new object[] { password }); user.commitchanges(); homecoming true; } grab (exception) { } homecoming false; } and when utilize it, throw exception : "the server unwilling process request. (exception hresult: 0x80072035)" @ line : "user.invoke("setpassword", new object[] { password });"
i tried many way cannot solve problem. help appricated. thanks
error 0x80072035 returns due password policy. can length, special characters, password history (password used before). help handle errors prrovide feedback user. guide handle these errors can found here:
http://www.ozkary.com/2015/03/active-directory-setpassword-or.html
c# active-directory
Comments
Post a Comment