Hi,
I have been trying to authenticate user using LDAP. But haven't been successful.
I am getting the following error and below is the code.:
try
{
for (int i = 0; i <=3; i++)
{
LdapAuthentication c = new LdapAuthentication();
if (c.IsAuthenticated(adPath,username,password))
return;
}
}
catch(Exception ex)
{
Console.WriteLine();
Console.WriteLine("Error authenticating. " + ex.Message+ "===" + ex.StackTrace);
}
Console.WriteLine("\nFinished all processing");
public bool IsAuthenticated(string path, string username, string pwd)
{
try
{
Console.WriteLine("\nNow trying... " + path + ", " + username + ", " + pwd);
DirectoryEntry entry = new DirectoryEntry( path, username, pwd);
Object obj = entry.NativeObject;
return true;
DirectorySearcher search = new DirectorySearcher(entry);
SearchResult res = search.FindOne();
if (null == res)
return false;
else
{
Console.WriteLine("Sucessful!! The correct answer is " + path + ", " + username + ", " + pwd);
return true;
}
}
catch (Exception ex)
{
Console.WriteLine("An Exception thrown= " + ex.Message+"===" + ex.StackTrace);
return false;
}
ERROR: An unhandled exception of type 'System.Runtime.InteropServices.COMException' occurred in system.directoryservices.dll
I also get - Logon failure: unknown user name or bad password
What went wrong? Please help me to debug the code.
Thanks in advance.