vb form to look at active directory services (1 Viewer)

sunshine076

Registered User.
Local time
Today, 00:22
Joined
Apr 6, 2009
Messages
160
I have created a vb form to access the server but when I click submit nothing happens to verify the user and then once the login has been verified I want it to go to another vb form. Any suggestions?

Imports System
Imports System.Text
Imports System.Collections
Imports System.DirectoryServices
Class MainForm
Dim i AsInteger
PrivateSub btnSubmit_Click(ByVal sender AsObject, ByVal e As EventArgs)
If txtUserName.Text.Trim().Equals("") OrElse txtPassword.Text.Trim().Equals("") Then
MessageBox.Show("Please Enter UserName/Password...")
txtPassword.Text = ""
txtUserName.Text = ""
Else
'if ADSI radio box is selected call ADSI Login else call simple database login
If rdoADSI.Checked = TrueThen
GetADSILogin()
Else
GetDatabaseLogin()
EndIf
EndIf
EndSub
'btnSubmit_Click
PublicSub GetADSILogin()
Try
Dim strServerName AsString = "\\mainsrv"
Dim strBaseDN AsString = "moeller"
Dim strUserDN AsString = ""
Dim strGroupName AsString = ""
Dim strAccountFilter AsString = ""
'Port no for LDAP Default is 389
Dim strPortNo AsString = "389"
Dim blnGroupUser As [Boolean] = False

If strParameterName.ToUpper().Equals("BASEDN") Then
strBaseDN = strParameterValue
EndIf
If strParameterName.ToUpper().Equals("USERDN") Then
strUserDN = strParameterValue
EndIf
If strParameterName.ToUpper().Equals("GROUPNAME") Then
strGroupName = strParameterValue
EndIf
If strParameterName.ToUpper().Equals("ACCOUNTFILTER") Then
strAccountFilter = strParameterValue
EndIf
EndWhile
EndIf'Search for user
Dim deSystem AsNew DirectoryEntry("LDAP://" + strServerName + "/" + strUserDN + "," + strBaseDN)
deSystem.AuthenticationType = AuthenticationTypes.Secure
deSystem.Username = txtUserName.Text
deSystem.Password = txtPassword.Text
'Search for account name
Dim strSearch AsString = strAccountFilter + "=" + txtUserName.Text
Dim dsSystem AsNew DirectorySearcher(deSystem, strSearch)
'Search subtree of UserDN
dsSystem.SearchScope = SearchScope.Subtree
'Find the user data
Dim srSystem As SearchResult = dsSystem.FindOne()
'Pick up the user group belong to
Dim valcol As ResultPropertyValueCollection = srSystem.Properties("memberOf")
If valcol.Count > 0 Then
Dim o AsObject
ForEach o In valcol
'check user exist in Group we are searching for
If o.ToString().Equals((strGroupName + "," + strBaseDN)) Then
blnGroupUser = True
ExitFor
EndIf
Next o
EndIf
If blnGroupUser = TrueThen
MessageBox.Show("Login Sucessfull...")
Else
MessageBox.Show("User Does Not Belong to Specified ADSI Group")
EndIf
Catch ex As Exception
MessageBox.Show(ex.Message)
EndTry
i = i + 1
If i = 5 Then
MessageBox.Show("Login failed for 5 times. Quiting...")
Me.Close()
EndIf
EndSub'GetADSILogin

 

Users who are viewing this thread

Top Bottom