|
This function can be used to access user information in the LDAP. First user have to enter username and password else obtain password from the back end.
Public Function GetAuthuserData(ByVal domain As String, ByVal username As String, ByVal pwd As String) As Boolean
Dim domainAndUsername
Dim arr(7) As String
domainAndUsername = domain & "\" & username
Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, pwd)
Try
'Information that user need to get from the LDAP
arr(0) = "LoginName"
arr(1) = "mail"
arr(2) = "cn"
arr(3) = "firstName"
arr(4) = "company"
arr(5) = "st"
arr(6) = "l"
arr(7) = "co"
Dim search As DirectorySearcher = New DirectorySearcher(entry, "(SAMAccountName=" + username + ")", arr)
Dim result As SearchResult
For Each result In search.FindAll()
Dim LoginName, FirstName, company, state, city, country, email As String
LoginName = GetProperty(result, "cn")
Session("LoginName") = LoginName
FirstName = GetProperty(result, "givenName")
Session("FirstName") = FirstName
company = GetProperty(result, "company")
Session("company") = company
state = GetProperty(result, "st")
Session("state") = state
city = GetProperty(result, "l")
Session("city") = city
country = GetProperty(result, "co")
Session("country") = country
email = GetProperty(result, "mail")
Session("email") = email
Next
If IsNothing(result) Then
Return False
End If
Catch ex As Exception
Return False
End Try
Return True
End Function
modified on Tuesday, June 3, 2008 5:15 AM
|
|
|
|