LDAP Login

I am trying to login user "vanbure" into my LDAP server.  LDAP Browser says the correct URL for this user is


yet my function below always returns False.

Function AuthenticateUser() As Boolean

        Dim de As New DirectoryEntry("LDAP://localhost:389/uid=vanbure,ou=users,ou=dmcs,dc=ed,dc=gov", "vanbure", "p@ssword1", AuthenticationTypes.Secure)                


            'run a search using those credentials.

            'If it returns anything, then you're authenticated

            Dim ds As DirectorySearcher = New DirectorySearcher(de)


            Return True


            'otherwise, it will crash out so return false

            Return False

        End Try

    End Function

 LDAP Browser says this is the properties of this user

uid = vanbure
sn = Van Buren
cn = Eric
userPassword = p@ssword1
Who is Participating?
CodeCruiserConnect With a Mentor Commented:
Here is an example


Public Function IsAuthenticated(ByVal domain As String, ByVal username As String, ByVal pwd As String) As Boolean

            Dim domainAndUsername As String = domain & "\" & username
            Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd)

                'Bind to the native AdsObject to force authentication.			
                Dim obj As Object = entry.NativeObject
                Dim search As DirectorySearcher = New DirectorySearcher(entry)

                search.Filter = "(SAMAccountName=" & username & ")"
                Dim result As SearchResult = search.FindOne()

                If (result Is Nothing) Then
                    Return False
                End If

                'Update the new path to the user in the directory.
                _path = result.Path
                _filterAttribute = CType(result.Properties("cn")(0), String)

            Catch ex As Exception
                Throw New Exception("Error authenticating user. " & ex.Message)
            End Try

            Return True
        End Function

Open in new window

Secure Authentication for LDAP is carried out on port 636, try that.

evanburenAuthor Commented:
I changed AuthenticationTypes.Secure to AuthenticationTypes.ServerBind because I can't use secure authentication and still no luck. I'm pretty sure it's the way that I'm passing the username and password or the LDAP url because this works

 Dim de As New DirectoryEntry("LDAP://localhost/ou=users,ou=dmcs,dc=ed,dc=gov", "cn=Manager,dc=ed,dc=gov", "secret", AuthenticationTypes.ServerBind)

this does not

 Dim de As New DirectoryEntry("LDAP://localhost:389/uid=vanbure,ou=users,ou=dmcs,dc=ed,dc=gov", "vanbure", "p@ssword1", AuthenticationTypes.ServerBind)              
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.