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)


%>

Here is some code that found in May:

'//////////////////////////////////////////////////////////////////////////
'/// Name:	ListADGroups.vbs
'/// Version:	1.0
'/// Date:	09/17/02
'/// Purpose: 	listing information about Active Directory groups
'/// OS:	Windows 2000, XP
'/// Reqs:	Account with permissions to read Active Directory groups properties
'/// Syntax:	cscript /nologo ListADGroups.vbs
'//////////////////////////////////////////////////////////////////////////

Option Explicit
On Error Resume Next

'////////////////////////////////////////////////////
'/// Variable Declarations

Dim oRootDSE, oCon, oCmd, oRecordSet
Dim sDomainADsPath, sUser, sPassword, sGroup, sProperties
Dim aDescription, aMember, iCount

'////////////////////////////////////////////////////
'/// Extract domain name of the logged on user account

Set oRootDSE 		= GetObject("LDAP://RootDSE")
sDomainADsPath		= "LDAP://" & oRootDSE.Get("defaultNamingContext")
Set oRootDSE 		= Nothing

'////////////////////////////////////////////////////
'/// Create, configure, and open ADO Connection object

Set oCon 		= CreateObject("ADODB.Connection")

oCon.Provider 		= "ADsDSOObject"

sUser			= "UserName"
sPassword		= "Password"	

oCon.Open "ADProvider", sUser, sPassword

'////////////////////////////////////////////////////
'/// Create and configure ADO Command object

Set oCmd		= CreateObject("ADODB.Command")
Set oCmd.ActiveConnection = oCon

sProperties		= "name,ADsPath,description,member"
sGroup			= "*"

oCmd.CommandText = "<" & sDomainADsPath & ">;(&(objectCategory=group)(name=" & sGroup & "));" & sProperties & ";subtree"
oCmd.Properties("Page Size") = 100
 
'////////////////////////////////////////////////////
'/// Populate ADO RecordSet object with AD Group info

Set oRecordSet = oCmd.Execute

'////////////////////////////////////////////////////
'/// Display results by listing all records in Recordset

WScript.Echo "Global Groups for the domain " & Replace(Mid(sDomainADsPath,11), ",DC=", ".")

While Not oRecordSet.EOF 
	WScript.Echo "Name: " & vbTab & oRecordSet.Fields("name")
	WScript.Echo "ADsPath: " & vbTab & oRecordSet.Fields("ADsPath") 
	aDescription = oRecordSet.Fields("description")
	If Not IsNull(aDescription) Then
		WScript.Echo "Description: " & vbTab & aDescription(0)
	End If
	aMember = oRecordSet.Fields("member")
	WScript.Echo "Members: "
	If Not IsNull(aMember) Then
		For icount = 0 to UBound(aMember)
			WScript.Echo vbTab & vbTab & aMember(iCount)
		Next
	End If
	oRecordSet.MoveNext 
Wend 

'////////////////////////////////////////////////////
'/// Close Recordset and Connection objects 

oRecordSet.Close
oCon.Close

'////////////////////////////////////////////////////
'/// Clean up 

Set oRecordSet = Nothing
Set oCon = Nothing
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.