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(); } } }
时间: 2024-10-21 18:12:57