vb6 & vb.net Ldap Authentication

Tags:
Development
I am developing desktop application which required to authentiate user through LDAP. I am looking for a general free dll or win/.net api to perform this task. Appreciate if you experts can help this. Sample code would be appreciated.

Answer Wiki

Thanks. We'll let you know when a new response is added.

Hi! Not my code by any means, and I haven’t tested. Hopefully it will provide a good starting point for you.

‘**************************************
‘ Name: LDAP Password Authentication
‘ Description:Show how to use LDAP to au
‘ thenticate users
‘ By: linda samson

‘ Inputs:LDAP Server, LDAP Port, UID, Or
‘ ganization, Organizational Unit, Passwor
‘ d

‘ Returns:True – if authenticated, False
‘ – if not

‘ Assumes:Requires Microsoft ActiveX Dat
‘ a Objects 2.0/2.1/2.5 Library
This is just a code snippet. You must supply the command button, etc.

‘This code is copyrighted and has’ limited warranties.Please see http://w
‘ ww.Planet-Source-Code.com/vb/scripts/Sho
‘ wCode.asp?txtCodeId=37354&lngWId=1′for details.’**************************************

‘linda
‘Requires Microsoft ActiveX Data Objects
‘ 2.0/2.1/2.5 Library (Project | Reference
‘ s)
‘TODO:
‘Private Sub Command1_Click()
‘Init()
‘msgbox Authenticate
‘End Sub
Dim m_LDAPServer as String
Dim m_LDAPPort as String
Dim m_Org as String
Dim m_OrgUnit as String
Dim m_Initial as String
Dim m_Password as String

Public Sub Init()
m_LDAPServer = “ldapserver.com”
m_LDAPPort= “389″
m_Org= “ldaporg.com” ‘o=
m_OrgUnit= “People” ‘ou=
m_Initial= “userId” ‘uid=
m_Password= “password”
End Sub

Public Function Authenticate() As Boolean
On Error Resume Next
Dim con As New Connection
Dim sqlStmt As String
Dim connStr As String
Dim rs As Recordset
‘TODO: trap blank UID and password here!

If (m_Initial = “”) Then
MsgBox “No Initial”
Exit Function
End If

If (m_Password = “”) Then
MsgBox “No Password”
Exit Function
End If
‘prepare SQL statement
sqlStmt = “SELECT uid ” & _
“FROM ‘LDAP://” & m_LDAPServer & “:” & m_LDAPPort & “/o=” & m_Org & “/ou=” & m_OrgUnit & “‘ ” & _
“WHERE uid=’” & m_Initial & “‘” & ” and objectClass=’*’”

‘create Active Directory Service Object
Set con = CreateObject(“adodb.connection”)
con.Provider = “ADSDSOOBject”

‘construct connection string
connStr = “uid=” & m_Initial & “,ou=” & m_OrgUnit & “,o=” & m_Org

‘open connection + password
con.Open “ADs Provider”, connStr, m_Password
‘execute our query
Set rs = con.Execute(sqlStmt)
‘rs will be empty if authentication fail
‘ s
Authenticate = Not (IsEmpty(rs) Or (Err.Number = -2147217911))
‘need to close
rs.Close
End Function

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following