LDAP Login

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

ldap://localhost:389/uid=vanbure,ou=users,ou=dmcs,dc=ed,dc=gov

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)                

        Try

            'run a search using those credentials.

            'If it returns anything, then you're authenticated

            Dim ds As DirectorySearcher = New DirectorySearcher(de)

            ds.FindOne()

            Return True

        Catch

            '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
.
evanburenAsked:
Who is Participating?
 
CodeCruiserConnect With a Mentor Commented:
Here is an example

http://support.microsoft.com/kb/326340


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)

            Try
                '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 & ")"
                search.PropertiesToLoad.Add("cn")
                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

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

0
 
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)              
0
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.