title: How to learn whether a user password is expired or not in Active Directory?
body: <p>In my ASP.NET MVC (C#) project I must learn whether a user password is expired or not? I found some answers about that on the internet but they didn't be useful for me.</p>
  
  <p>The first way to do using <code>maxpwdage</code> +<code>pwdlastset</code>= <code>password expired date</code>, and the second solution is that using <code>useraccountcontrol</code> attribute to learn whether it is expired or not. If this attribute's value is 8389120, user password is expired.</p>
  
  <p>Altough user password is expired in AD, <code>useraccountcontrol</code>value is still 512. I tried to do with <code>maxpwdage</code>+<code>pwdlastset</code> but I couldn't see an attribute like <code>maxpwdage</code> (I got users as an administrator)</p>
  
  <p><a href="https://stackoverflow.com/questions/3764327/active-directory-user-password-expiration-date-net-ou-group-policy">Active Directory user password expiration date .NET/OU Group Policy</a> <strong>(first way)</strong>
  <a href="https://support.microsoft.com/en-us/kb/305144" rel="nofollow noreferrer">https://support.microsoft.com/en-us/kb/305144</a> <strong>(second way)</strong></p>
  
  <p>Both of them aren't working because of reasons that I mentioned above.</p>
  
  <p>Are there any other ways to do this or how can i see value of the <code>maxpwdage</code> attribute?</p>
  
  <p><strong>EDIT</strong>: I am getting the user who i want from here</p>
  
  <pre><code>            DirectoryEntry dEntry = new DirectoryEntry
                          ( "LDAP://a.b.c:123/OU=d, DC=e, DC=f", this.GetAdUserName(),
                          this.GetAdUserPassword() );
              DirectorySearcher directorySearcher = new DirectorySearcher( dEntry );
              directorySearcher.Asynchronous = true;
              directorySearcher.CacheResults = true;
              directorySearcher.Filter = "(&amp;(sAMaccountName=" + identificationNumber + "))";
              SearchResult user = directorySearcher.FindOne();
              return user;
  </code></pre>
  
  <p>I am checking user's properties but I couldn't find <code>maxpwdage</code> property.</p>