This code shows an example of how to validate a domain username password programmatically.
string username = "...";
string password = "...";
PrincipalContext principalContext = new PrincipalContext(ContextType.Domain);
if (principalContext.ValidateCredentials(username, password))
{
Console.WriteLine($"Authenticated user: {username}");
}
else
{
Console.WriteLine($"Authentication failed for user: {username}");
}