|
VB.NET • Authenticate Against an Active Directory Source Listing 4. This version of the Validate method uses an Active Directory. You use Lightweight Directory Access Protocol (LDAP) as the transport protocol to communicate with the Active Directory server. Public Function Validate() as Boolean
' This is the pointer to the PDC
Shared strLDAPPath As String = _
"LDAP://PDC_SERVERNAME"
Shared strDomainName As String = _
"@YOURDOMAIN.COM"
Dim dirEntry As DirectoryEntry
Dim dirSearcher As DirectorySearcher
Dim objGUID As String = ""
Dim strNameEntry As String
' Try to get the Name property from the AD.
' If you can do this with the current
' userID and Password, then the credentials
' must be OK.
Try
dirEntry = New DirectoryEntry _
(strLDAPPath, strUserID & _
strDomainName, strPassword)
strNameEntry = _
dirEntry.Properties("Name").ToString
Catch except As Exception
Return False
End Try
Return True
End Function
|