ADAM user's password reset with c#

416 views Asked by At

I am trying to reset user passowrd in ADAM. For that I am using Accountmanagement namesapce

what i tried :

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;

for password reset :

 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"

I have checked none of the string is empty and also tried contextOption.secureSocketlayer but nothing works

do i need to provide an encrypted password? or do i need to set any property ? Thanks in advance.

1

There are 1 answers

0
AnandSonake On

Well I got the solution. Just remove

ContextOptions.Negotiate 

while instantiating rootprincipalContext.

And use ExpirePasswordNow() method before SetPassword().