Authenticate User Active Directory Credentials in C#
public static bool AuthenticateAD(string username, string password)
{
using(var context = new PrincipalContext(ContextType.Domain, "DOMAIN"))
{
return context.ValidateCredentials(username, password);
}
}
// using sAMAccountName version of username:
if (AuthenticateAD("DOMAIN\\username", "pass"))
{
Console.WriteLine("Authenticated");
}
// using UPN version of username:
if (AuthenticateAD("username@DOMAIN.net", "pass"))
{
Console.WriteLine("Authenticated");
}