用c#重置ADAM用户密码
问题描述:
我正在尝试在ADAM中重置用户密码。对于我使用Accountmanagement namesapce用c#重置ADAM用户密码
我的尝试:
PrincipalContext rootPrincipalContext;
LdapConnection objLdapconnection;
rootPrincipalContext = new PrincipalContext(ContextType.ApplicationDirectory, host, baseDN, ContextOptions.Negotiate, username, password);
LdapDirectoryIdentifier identifier = new LdapDirectoryIdentifier(host, Convert.ToInt32(port));
NetworkCredential credential = new NetworkCredential(username, password);
LdapConnection ldapCon = new LdapConnection(identifier, credential);
ldapCon.AuthType = AuthType.Negotiate;
objLdapconnection = ldapCon;
密码重置:
UserPrincipal existingUsr = UserPrincipal.FindByIdentity(rootPrincipalContext, IdentityType.DistinguishedName, "cn=" + inputName + ",ou=gslab,dc=starfish");
existingUsr.SetPassword(userPassvalue); this lines throws exception "directory property can not be found"
我已经检查没有字符串是空的,也试过contextOption.secureSocketlayer但没有作品
我需要提供加密密码吗?还是我需要设置任何属性?提前致谢。
答
那么我得到了解决方案。只要删除
ContextOptions.Negotiate
而实例化rootprincipalContext
。
并在SetPassword()
之前使用ExpirePasswordNow()
方法。