using System.DirectoryServices;
/// <summary>
/// AD账号登陆验证
/// </summary>
/// <param name="UserName">AD用户名</param>
/// <param name="PassWord">AD密码</param>
/// <param name="strOU">active directory 中的组织单位</param>
/// <returns></returns>
public bool Login(string UserName, string PassWord, string strOU)
{
String strPath = string.Format("LDAP://OU={0},OU=ZYE,DC=zhanyun,DC=com,DC=cn", strOU);
DirectoryEntry AD = new DirectoryEntry(strPath);
AD.Username = "zhanyun" + @"" + UserName;
AD.Password = PassWord;
try
{
DirectorySearcher searcher = new DirectorySearcher(AD);
searcher.Filter = String.Format("(sAMAccountName={0})", UserName);
System.DirectoryServices.SearchResult result = searcher.FindOne();
if (result == null)
{
return false;
}
AD.Close();
}
catch
{
return false;
}
finally
{
AD.Close();
}
return true;
}
bool result = Login(username, password, "MIS");