Home >Backend Development >C++ >How Can I Verify Active Directory User Credentials in C#?

How Can I Verify Active Directory User Credentials in C#?

Susan Sarandon
Susan SarandonOriginal
2025-01-31 09:41:14640browse

How Can I Verify Active Directory User Credentials in C#?

Verify Active Directory user credentials in C#

Question:

How to determine the effectiveness of the username and password of Active Directory authentication?

Answer:

For applications deployed on .NET 3.5 and higher versions, System.directoryServices.accountManagement The naming space provides an efficient verification proof mechanism:

This method is simple and reliable, and it is realized in pure C#.

<code class="language-csharp">using(PrincipalContext pc = new PrincipalContext(ContextType.Domain, "YOURDOMAIN"))
{
    // 验证凭据
    bool isValid = pc.ValidateCredentials("myuser", "mypassword");
}</code>
Document reference:

.NET Framework 3.5 Directory Security Main Management

    System.directoryServices.accoundManagement
  • Note:
  • As mentioned in the related Stack Overflow discussion, this method may sometimes return "True" to the expired user password. When explaining the verification results, please pay attention to this potential behavior.

The above is the detailed content of How Can I Verify Active Directory User Credentials in C#?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn