title: AccessDenied while using UserPrincipal SetPassword method
body: <p>I am getting an <strong><em>AccessDenied</em></strong> exception while changing user's password using <strong><em><a href="http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.userprincipal%28v=vs.100%29.aspx" rel="nofollow">UserPrincipal</a></em></strong> class.</p>
  
  <p>I am logging to an Asp.Net application through <strong>Windows Authentication</strong> <em>(domain user)</em>. If I try to change other user's password I am getting the access denied exception. If I am doing the same with user that I am logged in, everything is OK - I can change password. </p>
  
  <p>I thought, that if I will get <strong><em>UserPrincipal</em></strong> object using <strong><em>PrincipalContext</em></strong>, I will do anything to which my 'Principal - <em>domain\adminAD</em>' has privilidges in AD.</p>
  
  <p>Body of method:</p>
  
  <pre><code>public bool SetPassword(string userName, string password)
  {
      var saved = false;
  
      var ldapDomainName = "domain";
      var ldapUsersOU = "OU=TEST,DC=domain,DC=com";
      var ldapLogin = "domain\adminAD";
      var ldapPassword = "password";
  
      try
      {
          using (var principalContext = new PrincipalContext(
             ContextType.Domain,
             ldapDomainName,
             ldapUsersOU,
             ContextOptions.Signing | ContextOptions.Sealing | ContextOptions.Negotiate,
             ldapLogin,
             ldapPassword))
          {
              userPrincipal = UserPrincipal.FindByIdentity(principalContext, IdentityType.SamAccountName, userName);
              userPrincipal.SetPassword(password);
              userPrincipal.Save(principalContext);
              saved = true;
          }
       }
       catch (Exception ex)
       {
          // Log exception
       }
  
       return saved;
    }
  </code></pre>
  
  <hr>
  
  <p>I have already searched for the answer and I know that there are plenty of answers to similar topics. But none of them explain my problem, I guess.</p>