Question Active Directory Groups in VS2008

flaps

New member
Joined
Sep 18, 2008
Messages
3
Programming Experience
Beginner
Hi all,

I am writing an application where active directory validation is required before accessing the main form. There are 2 forms. Form 2 is the login form and form 1 is the main form. The main form would have a simple look, with about 10 checkboxes.
I have managed to get the authentication working great... but what now need to do is validate groups. Say if "user A" is in "groups A,B and C" and "user B" is in "groups B and C" i would like for them to use my login form, once they log in, the groups that they are members of would appear in a listbox on either form, (whichever is easiest) and is hidden from the user ... if they are in group A, then the main form would show only the first 3 checkboxes, if they are in group B, then it would show the 4th and 5th checkboxes, if in both groups then show the first 5 checkboxes etc.
It is a simple idea, but is complicated to explain.
As i said, the login form is working with the active directory... here is the code for the login form:

VB.NET:
Public Class Form2 
 
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 
        Dim isauthenticated As Boolean = AuthenticateUser() 
        If isauthenticated Then 
            MsgBox("Login Successful") 
            Form1.Show() 
            Me.Hide() 
        Else 
            MsgBox("Login Failed") 
        End If 
    End Sub 
 
    Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean 
        Dim Success As Boolean = False 
        Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" & Domain, Username, Password) 
        Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry) 
        Searcher.SearchScope = DirectoryServices.SearchScope.OneLevel 
        Try 
            Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne 
            Success = Not (Results Is Nothing) 
        Catch 
            Success = False 
        End Try 
        Return Success 
    End Function 
 
    Private Function AuthenticateUser() As Boolean 
        Dim username As String = TextBox1.Text 
        Dim password As String = TextBox2.Text 
        Dim domain As String = TextBox3.Text 
 
        Dim isAuthenticated As Boolean = ValidateActiveDirectoryLogin(domain, username, password) 
 
        Return isAuthenticated 
    End Function 
 
 
 
    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 
        Me.Close() 
    End Sub



as you can see it is very simple and works well.

Form1 in the code is my main form, and wish for it to change according to which groups the user is in.

Any help would be much appreciated.

Regards
 
Managing a dynamic number of checkbox options is far easier using the CheckedListBox control than a multiple CheckBox controls.
 
thanks for your reply... would you know how I would go about this with managing the checkedlistbox control and making certain aspects of this control visible to certain groups in the active directory?
Sorry i know this sounds confusing lol, its pretty hard to explain
 
I was more thinking you could add dynamically the options that were to be made available, clb.Items.Add("option A")
 
Back
Top