I have three issues that I am struggling with in my code for authenticating users in AD.
1. I want to pass the Username to the next page so that I can use it in an Audit Trail later on during the users experience with the app. I do not want to use a query string.
2. I want to get the users First and Last Name after authenticating. I have no clue how to do this and no clear explanation on the web has been found.
3. I want the user to be a member a specific group in AD. I am using LDAP
Can anyone help me thorugh these issues? I have included my code below - works fine except that any member of the domain can login..not just members of the group
I am assuming that the majority of the code needs to go here except for the username,etc that will passed off to the next page.
I have this for getting at the specific group but I can not figure out how to use this in my code. As is - does not work.
=ABC Managed Users,OU=Users,OU=MySite,O
Partial Class Authenticate_With_Active_Directory
Protected Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim isAuthenticated As Boolean = AuthenticateUser()
If isAuthenticated Then
Dim sScript As String
Dim cScript As String
Incorrect.visible = True
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
Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
Success = Not (Results Is Nothing)
Dim aCookie As New HttpCookie("lastVisit")
aCookie.Values("userName") = txtUserName.Text
aCookie.Values("lastVisit") = DateTime.Now.ToString()
aCookie.Expires = DateTime.Now.AddHours(4)
Success = False
Private Function AuthenticateUser() As Boolean
Dim username As String = txtUsername.Text
Dim password As String = txtPassword.Text
Dim domain As String = "my.domain.org"
Dim isAuthenticated As Boolean = ValidateActiveDirectoryLogin(domain, username, password)