LDAP Login

Posted on 2011-10-08
Last Modified: 2012-05-12
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
Question by:evanburen
    LVL 9

    Expert Comment

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


    Author Comment

    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)              
    LVL 83

    Accepted Solution

    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


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Installing a printer using group policy preferences is not that hard let’s take a look at it. First lets open up your group policy console and edit the policy you want to add it to. I recommend creating a new policy for each printer makes it a l…
    Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
    This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…
    This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now