R
Raghu
I have following code that validates a given user credentails against a
active directory. The login part works but I can not search fails to return
the record. Does any one have any idea what is wrong?
public void Login(string user, string pwd, string domain)
{
string path = "<<my ldap path>>";
DirectoryEntry domainEntry = new DirectoryEntry(path);
domainEntry.Username = domain + @"\" + user;
domainEntry.Password = pwd;
domainEntry.AuthenticationType = AuthenticationTypes.Secure;
string searchFilter = "sAMAccountName=" + user;
DirectorySearcher searcher = new DirectorySearcher(domainEntry,
searchFilter);
searcher.SearchScope = SearchScope.Subtree;
//The following line throws exception if supplied user
credentails are not valid
SearchResult result = searcher.FindOne();
Console.WriteLine("Login succeeded.");
if (result == null)
{
Console.WriteLine("Search for user failed.");
Console.WriteLine();
}
else
{
Console.WriteLine("Search for user succeeded.");
}
}
Thanks.
Raghu/..
active directory. The login part works but I can not search fails to return
the record. Does any one have any idea what is wrong?
public void Login(string user, string pwd, string domain)
{
string path = "<<my ldap path>>";
DirectoryEntry domainEntry = new DirectoryEntry(path);
domainEntry.Username = domain + @"\" + user;
domainEntry.Password = pwd;
domainEntry.AuthenticationType = AuthenticationTypes.Secure;
string searchFilter = "sAMAccountName=" + user;
DirectorySearcher searcher = new DirectorySearcher(domainEntry,
searchFilter);
searcher.SearchScope = SearchScope.Subtree;
//The following line throws exception if supplied user
credentails are not valid
SearchResult result = searcher.FindOne();
Console.WriteLine("Login succeeded.");
if (result == null)
{
Console.WriteLine("Search for user failed.");
Console.WriteLine();
}
else
{
Console.WriteLine("Search for user succeeded.");
}
}
Thanks.
Raghu/..