title: UserPrincipal.FindByIdentity Permissions
body: <p>I'm attempting to use the .NET <code>System.DirectoryServices.AccountManagement</code> library to obtain the UserPrincipal for a particular Active Directory user.</p>
  
  <p>I've got the following code:</p>
  
  <pre><code>PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName");
  userPrincipal = UserPrincipal.FindByIdentity(context, IdentityType.SamAccountName, username);
  </code></pre>
  
  <p>This code is running as a valid domain user, but when I execute it I get the following exception:</p>
  
  <blockquote>
    <p>System.DirectoryServices.DirectoryServicesCOMException (0x8007052E): Logon failure: unknown user name or bad password.</p>
  </blockquote>
  
  <p>What's interesting is that I can make the following call, using the same context, without a problem:</p>
  
  <pre><code>context.ValidateCredentials(username, password, ContextOptions.Negotiate)
  </code></pre>
  
  <p>Ideas?</p>