Hello!
I am currently doing some authentication in Active Directory.
Our AD is running in Windows 2008 Server and I manage to log-in based in our AD. However I also want to get the group where the user belongs. but I don't know how. Can anyone help me?
here is the authentication in AD I copied...
<%@ Language="VBScript" %>
<%
Option Explicit
Response.Buffer = True
'// 1. Form Validation
Dim Submit, UserName, Password, Domain, Result, Message
Submit = "Authenticate"
'Assume Failure
Application("Error")= true
If Submit = "Authenticate" Then
response.write("autenthication <br>")
'Get the input from your HTML form
UserName = Request.Form("UserName")
Password = Request.Form("Password")
Domain = Application("Domain")
Session("usern") = UserName
'Call the AuthenticateUser() function to do the verification process
Result = AuthenticateUser(UserName, Password, Domain)
If Result Then
'If user exist, then redirect to success page
'login success
Application("Error")= false
Response.Redirect ("success.asp")
Else
'If user don't exist, redirect to error page
'login failed
Application("Error")= true
Response.Redirect ("../")
End If
End If
'// 2. Authenticate Function
Function AuthenticateUser(UserName, Password, Domain)
Dim strUser, strPassword, strQuery, oConn, cmd, oRS
'Assume Failure
AuthenticateUser = false
strQuery = "SELECT cn FROM 'LDAP://" & Domain & "' WHERE objectClass='*'"
Set oConn = server.CreateObject("ADODB.Connection")
oConn.Provider = "ADsDSOOBJECT"
oConn.Properties("User ID") = UserName
oConn.Properties("Password") = Password
oConn.Properties("Groups") = "SALES"
oConn.Properties("Encrypt Password") = true
oConn.open "ADProvider", strUser, strPassword
Set cmd = server.CreateObject("ADODB.Command")
Set cmd.ActiveConnection = oConn
cmd.CommandText = strQuery
On Error Resume Next
Set oRS = cmd.Execute
If oRS.bof OR oRS.eof Then
AuthenticateUser = False
Else
AuthenticateUser = True
End if
Set oRS = Nothing
Set oConn = nothing
End Function
'############### CHECKER #########
response.write(myString)
%>