I just installed Visual Studio .net 2013 pro. I am using Win 7 enterprise.
I am trying to create a concept test program to learn how to authenticate a user against our Active Directory. I am using Visual Basic.Net. NOT ASP.NET
I created a form. On the form there are 3 text boxes and a button.
The text boxes are used to input the domain name, the user name, and the user password.
Clicking the button will cause the program to use the log in info from the text boxes to query AD and see if the account and password are legit. If so a message box will say it is legit, if not a message box will say it is not.
I found some code on one of the many web sites with VB help, actually I have seen variations of it in many places, that looks like it may do the trick for me but Vb tells me "Type 'System.DirectoryServices.DirectoryEntry' is not defined".
I have not found a solution to that error.
The code is as follows...
Any suggestions on how to get this to work would be greatly appreciated.
Thanks,
Ralph
I am trying to create a concept test program to learn how to authenticate a user against our Active Directory. I am using Visual Basic.Net. NOT ASP.NET
I created a form. On the form there are 3 text boxes and a button.
The text boxes are used to input the domain name, the user name, and the user password.
Clicking the button will cause the program to use the log in info from the text boxes to query AD and see if the account and password are legit. If so a message box will say it is legit, if not a message box will say it is not.
I found some code on one of the many web sites with VB help, actually I have seen variations of it in many places, that looks like it may do the trick for me but Vb tells me "Type 'System.DirectoryServices.DirectoryEntry' is not defined".
I have not found a solution to that error.
The code is as follows...
Code:
Public Class FrmLogin
Private Sub btLogin_Click(sender As Object, e As EventArgs) Handles btLogin.Click
If txtDomain.Text = "" Then
MsgBox("You need to input a domain name", 0, "Missing Domain Name")
Exit Sub
End If
If txtUserName.Text = "" Then
MsgBox("You need to input a UserName", 0, "Missing Username Name")
Exit Sub
End If
If txtUserPassword.Text = "" Then
MsgBox("You need to provide a password", 0, "Missing Password")
Exit Sub
End If
If ValidateActiveDirectoryLogin(txtDomain.Text, txtUserName.Text, txtUserPassword.Text) Then
MsgBox("User: " & txtDomain.Text & "\" & txtUserName.Text & " has been loged in.", vbOKOnly + vbInformation, "Login Results")
Else
MsgBox("User: " & txtDomain.Text & "\" & txtUserName.Text & " Could not be loged in!", vbOKOnly + vbCritical, "Login Results")
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
End Class
Thanks,
Ralph