Public bool IsPass (string userAccount, string password)
{
String DomainName = "DC = SYQUEYRY, DC = COM, DC = CN ";
String ADPath = "LDAP: // SYQUEYRY. COM. CN ";
String ADDomain = "SYQUEYRY ";
// Obtain the path in the current domain
String _ ADPath = ADPath + "/" + ADDomain;
String domainAndUsername;
Bool hasDomain = false;
If (userAccount. StartsWith (DomainName, StringComparison. CurrentCultureIgnoreCase ))
{
HasDomain = true;
}
If (hasDomain)
{
DomainAndUsername = userAccount;
}
Else
{
DomainAndUsername = DomainName + @ "\" + userAccount;
}
DirectoryEntry entry = new DirectoryEntry (_ ADPath, domainAndUsername, password );
DirectorySearcher search = new DirectorySearcher (entry );
If (hasDomain)
{
UserAccount = userAccount. Substring (DomainName. Length + 1 );
}
Search. Filter = "(sAMAccountName =" + userAccount + ")";
Search. PropertiesToLoad. Add ("displayName ");
SearchResult adUser = null;
Try
{Www.2cto.com
AdUser = search. FindOne ();
If (adUser = null)
{
_ Error = "domain authentication failed ";
}
Else
{
If (Convert. ToInt32 (adUser. Properties ["userAccountControl"] [0]) = 2)
{
_ MyUser = new MyUser (userAccount, password, adUser. Properties ["displayName"]. ToString ());
}
Else
{
_ Error = "this user has been disabled ";
}
AdUser = null;
}
}
Catch (Exception ex)
{
_ Error = ex. Message;
AdUser = null;
}
Finally
{
Entry. Close ();
Entry = null;
Search. Dispose ();
Search = null;
}
Return adUser! = Null;
}
Author Jia Shiyi