域账户密码登录验证

https://files.cnblogs.com/files/shexunyu/%E5%9F%9F%E8%B4%A6%E6%88%B7%E5%AF%86%E7%A0%81%E7%99%BB%E5%BD%95%E9%AA%8C%E8%AF%81.zip

public class VerifyUserByDomain
{
  public static bool verify(string userName, string pwd, string domain)
  {
    bool boolResult = false;
  try
  {
    //连接域,path通常是:"LDAP://****";****为域的名字(一般是大写的英文字符串)
    DirectoryEntry dirEntry = new DirectoryEntry("LDAP://" + domain, userName, pwd);
    //string strFilter = "(&(objectCategory=person)(objectClass=user))";
    string strFilter = string.Format("(&(objectClass=user)(samAccountName={0}))", userName);
    DirectorySearcher objSearcher = new DirectorySearcher(dirEntry, strFilter);
    SearchResult result = objSearcher.FindOne();
    boolResult = true;
  }
  catch (Exception ex)
  {
    throw ex;
  }
    return boolResult;
  }
}

 

posted on 2018-02-07 15:33  shexunyu  阅读(451)  评论(0编辑  收藏  举报

导航