使用ADSI如何验证输入的用户名和口令是否正确,可以登录?

解决方案 »

  1.   

    ADSI?是不是指ADSL?
    请LZ说清楚一点
      

  2.   

    /// <summary>
    /// Method to validate if a user exists in the AD.
    /// </summary>
    /// <param name="UserName">user logon name</param>
    /// <returns></returns>
    public bool UserExists(string UserName)
    {
    DirectoryEntry de = ADHelper.GetDirectoryEntry();
    DirectorySearcher deSearch = new DirectorySearcher();
    deSearch.SearchRoot =de;
    deSearch.Filter = "(&(objectClass=user) (sAMAccountName=" + UserName +"))"; 
    SearchResultCollection results = deSearch.FindAll();
    if(results.Count == 0)
    {
    return false;
    }
    else
    {
    return true;
    }
    }