C# AD 验证登陆

using System.DirectoryServices;
using System.DirectoryServices.AccountManagement;  

using (DirectoryEntry adsEntry = new DirectoryEntry("LDAP://test.com", userName, password, AuthenticationTypes.Secure))
                {
                    using (DirectorySearcher adsSearcher = new DirectorySearcher(adsEntry))
                    {
                        adsSearcher.Filter = "(sAMAccountName=" + userName + ")";
                        try
                        {
                            SearchResult adsSearchResult = adsSearcher.FindOne();                            
                        }
                        catch (Exception ex)
                        {
                            // 用户名或密码错误
                            string strError = ex.Message;
                        }
                        finally
                        {
                            adsEntry.Close();
                        }
                    }
                }
原文地址:https://www.cnblogs.com/lishidefengchen/p/5741202.html