You need to reference System.DirectoryServices
You also need to know the ActiveDirectory path (ADPath)
We use this code to authenticate a user
public static bool IsADSUser(string userAlias, string pwd)
{
#region Source
bool isADSUser = false;
if (userAlias.Trim().Length == 0 || pwd.Length == 0)
{
isADSUser = false;
}
else
{
string filter = String.Format("(&(objectCategory=organizationalPerson)(samaccountname={0}))", userAlias);
DirectoryEntry de = new DirectoryEntry(ADPath, userAlias, pwd, AuthenticationTypes.Secure);
DirectorySearcher ds = new DirectorySearcher(de);
ds.ReferralChasing = ReferralChasingOption.All;
ds.Filter = filter;
SearchResult result = null;
using (de)
{
using (ds)
{
try
{
result = ds.FindOne();
}
catch (Exception ex)
{
if (ex.Message.Contains("Logon failure:"))
{
result = null;
}
else
{
throw ex;
}
}
}
}
if (result != null)
{
isADSUser = true;
}
else
{
isADSUser = false;
}
}
return isADSUser;
#endregion
}