public bool IsADAuthenticated(string
domain, string username, string pwd)
{
string _path =
System.Configuration.ConfigurationManager.AppSettings["DomainPath"];
string _filterAttribute =
string.Empty;
string domainAndUsername = domain +
@"\" + username;
DirectoryEntry entry = new
DirectoryEntry(_path, domainAndUsername, pwd);
try
{
object obj =
entry.NativeObject;
DirectorySearcher search = new
DirectorySearcher(entry);
search.Filter =
"(SAMAccountName=" + username + ")";
search.PropertiesToLoad.Add("cn");
SearchResult result =
search.FindOne();
if (null == result)
{
return false;
}
_path = result.Path;
_filterAttribute =
(string)result.Properties["cn"][0];
}
catch (Exception)
{
lblError.Text =
UtilityClass.NotificationMessages.IncorrectCredentials;
return false;
}
return true;
}