Authenticating LDAP user in VB.NET or ASP.NET
If you want to authenticate user against LDAP using VB.NET or ASP .NET.
Below is the function, you can try. Don't forget to import System.DirectoryServices in your codes.
Public Function AuthenticateUser(ByVal ldapServerName As String, ByVal username As String, ByVal password As String) As Boolean
Dim _ldapServerName = ldapServerName
Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & ldapServerName & _
"/uid=""" & username & """,ou=yourfullOU", "uid=""" & username & """,ou=yourfullOU", password, AuthenticationTypes.ServerBind)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
Try
Dim mySearchResult As SearchResult = oSearcher.FindOne()
Return True
Catch e As Exception
MsgBox("Error is " & e.Message)
Return False
End Try
End Function
Below is the function, you can try. Don't forget to import System.DirectoryServices in your codes.
Public Function AuthenticateUser(ByVal ldapServerName As String, ByVal username As String, ByVal password As String) As Boolean
Dim _ldapServerName = ldapServerName
Dim oRoot As DirectoryEntry = New DirectoryEntry("LDAP://" & ldapServerName & _
"/uid=""" & username & """,ou=yourfullOU", "uid=""" & username & """,ou=yourfullOU", password, AuthenticationTypes.ServerBind)
Dim oSearcher As DirectorySearcher = New DirectorySearcher(oRoot)
Try
Dim mySearchResult As SearchResult = oSearcher.FindOne()
Return True
Catch e As Exception
MsgBox("Error is " & e.Message)
Return False
End Try
End Function