authenticate against AD

magmo

Member
Joined
Oct 19, 2006
Messages
14
Programming Experience
1-3
Hi

I have this piece of code that just check username and password against a Active directory. If I also would like to filter against a specific group name how would I then do?

HTML:
    Public Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String, ByVal GroupName As String) As Boolean
        Dim Success As Boolean = False
        Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://192.168.0.1/DC=" & Domain, Username, Password)
        Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
        Searcher.SearchScope = DirectoryServices.SearchScope.Subtree
        Try
            Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
            Success = Not (Results Is Nothing)
        Catch
            Success = False
        End Try
        Return Success
    End Function


Best Regards
 
Try adding this:

searcher.PropertiesToLoad.AddRange(NewString() {"memberOf"})

Then iterate through the groups

If Not IsNothing(result.Properties("memberOf")) Then

For Each propertyValue As String In result.Properties("memberOf")
Dim groupName As String = propertyValue
If Not IsNothing(groupName) Then
' do your comparison here or just print them out to see if you get them first
End If



Next



End If
 
Back
Top