Logon failure: unknown user name or bad password... LDAP Authentication

Last post 05-02-2008 3:53 PM by maru.purvi. 0 replies.

Sort Posts:

  • Logon failure: unknown user name or bad password... LDAP Authentication

    05-02-2008, 3:53 PM
    • Loading...
    • maru.purvi
    • Joined on 05-02-2008, 3:38 PM
    • Posts 1
    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.
Page 1 of 1 (1 items)