DirectoryServicesCOMException: Logon failure: unknown user name or bad password. Please help.

Last post 05-13-2009 12:41 PM by Vimpyboy. 1 replies.

Sort Posts:

  • DirectoryServicesCOMException: Logon failure: unknown user name or bad password. Please help.

    05-13-2009, 12:07 PM
    • Member
      2 point Member
    • planet_x
    • Member since 05-13-2009, 3:54 PM
    • Posts 15

    Having an issue migrating from Visual Studio 2003 to 2005 and using asp.net 2.0 to validate local users. Code was the same as before and was working correctly except now I get an exception on the line results = mySearcher.FindAll(). Just wondering if LDAP is changed and if the below code is incorrect, searched various places and cannot find a solution yet. Any help appreciated.

    Public Function GetUserFullName(ByVal username As String) As String
                Dim
    entry As New DirectoryEntry("LDAP://NETADDRESS")
         Dim mySearcher As New DirectorySearcher(entry)
                'Dim result As SearchResult
                mySearcher.Filter = ("(&(objectClass=user)(SAMAccountName=" & username & "))")
                Dim results As SearchResultCollection
                results = mySearcher.FindAll()
                Select Case results.Count
                    Case 0
                        Return "False"
                    Case 1
                        Dim Name() As String = Split(results(0).GetDirectoryEntry().Name, "=")
                        Return Name(1)
                    Case Is > 1
                        'Return "Multiple"
                        Dim Name() As String = Split(results(0).GetDirectoryEntry().Name, "=")
                        Return Name(1)
                End Select
                Return Nothing
            End Function

     
    Filed under: , ,
  • Re: DirectoryServicesCOMException: Logon failure: unknown user name or bad password. Please help.

    05-13-2009, 12:41 PM
    Answer
    • Contributor
      2,865 point Contributor
    • Vimpyboy
    • Member since 03-26-2003, 4:12 AM
    • Stockholm, Sweden
    • Posts 589

    You need to send your credentials to the DirectoryEntry before searching.

     

    entry.Username = "domain\username"; 
    entry.Password = "password";
     

     

    Mikael Söderström
Page 1 of 1 (2 items)