Solved

Issues with Active Directory authentication through VBScript in an HTA

Posted on 2009-05-12
4
3,105 Views
Last Modified: 2013-12-24
I am using an HTA script to authenticate specific users against Active Directory.

The failure portion of the script works correctly, but when the user is an authorized user the script does nothing.  After running Wireshark to see what if the query was happening, it seems as though it does the query against AD and doesn't do anything with the results.

Below is the code...please help
<script language="vbscript">
 
'==============================================================================
'Author:		David Halliday
'Date:			11/6/2008
'Script Name:		Auth.hta
'Purpose:		This page is a compilation of functions that run in 
'			an HTML Application (HTA).  This page will authenticate an 
'			Administrator account that resides in the Active Directory 
'			path: "<InsertLDAPPath>" and allow them 
'			to continue on to the SCCM.hta file to create the necessary
'			accounts.
'
'Included Functions (w/ Description):
'Primary Functions
'	cmdSubmit_OnClick(): Function used to parse the provided user information
'		to the Authentication Function when the Submit button is clicked on
'		the page.
'	Authenticate(): Main script used to authenticate the user information 
'		with Active Directory. This will also log the Administrator 
'		information if the authentication is successful or if it fails.
'
'==============================================================================
 
Function setSize()
 
window.resizeTo 375,200
 
End Function
 
Function cmdSubmit_OnClick()
'==============================================================================
'Name:			cmdSubmit
'Description:		Function used to parse the provided user information
'		to the Authentication Function when the Submit button is clicked on
'		the page.
'Passed Variables:	strAdmin, strPW
'Output Variables:	strAdmin, strPW
'==============================================================================
 
Dim strAdmin		'Administrator's User Name variable
Dim strPW 			'Administrator's Password variable
 
 
 
					    
if auth.username.value = "" Then
	msgbox ("ERROR: No admin account information provided. Please Try Again!")
	cmdSubmit_OnClick = False
 
Elseif auth.password.value = "" Then
	msgbox ("ERROR: No admin account information provided. Please Try Again!")
	cmdSubmit_OnClick= False
 
Else
 
 
 
strAdmin = auth.username.value
strPW = auth.password.value
 
End If
 
						
	Authenticate strAdmin, strPW
		
	'window.close()
	
End Function
 
Public Sub Authenticate (Byref strAdmin, Byref strPW)
'==============================================================================
'Name:			Authenticate
'Description:		Main script used to authenticate the user information 
'		with Active Directory. This will also log the Administrator 
'		information to a specified directory and file if the authentication is 
'		successful or if it fails.
'Passed Variables:	strAdmin, strPW, dirLog, strALog
'Output Variables:	strAdmin
'==============================================================================
 
On Error Resume Next
 
CONST ADS_SECURE_AUTHENTICATION = 1
 
 
Dim strPath			'LDAP path where the Administrator accounts are listed
Dim LDAP 			'Directory Service Object reference variable
Dim strAuth			'Parses the User Name and Password through the DSObject
 
 
strPath = "LDAP://<Insert Proper LDAP Path>"
 
 
Set LDAP = GetObject("LDAP:")
 
 
Set strAuth = LDAP.OpenDSObject(strPath, strAdmin, strPW, ADS_SECURE_AUTHENTICATION + ADS_SERVER_BIND)
 
If Err.number <> 0 Then
	intTemp = msgbox(strAdmin & " could not be authenticated", vbYES)
	if intTemp = vbYes Then
	window.location.reload()
	End If
Else
	For Each obj in strAuth
		If obj.Class = "user" Then
			If obj.Get("samAccountName") = strAdmin Then
				msgbox ("Success! " & strAdmin & " has been authenticated" &_
					" with Active Directory")
				Set objShell = CreateObject("Wscript.shell")
				objShell.run ("mshta.exe c:\sccm.hta")
			End If
		End If
	Next
End If
 
 
End Sub
 
 
 
</script>
 
 
<body onload="vbs:setSize()">
<div class="style2">
 
	<h3>Administrator Authentication</h3>
 
</div>
 
 
 
<form method="post" id="auth" name="auth">
	<span class="style3"><strong>User Name:&nbsp; </strong></span> 
	<input id="username" name="username" type="text" style="width: 150px" /><br>
	<span class="style3">
	<strong>Password:&nbsp;&nbsp;&nbsp;&nbsp;    </strong></span> 
	<input id="password" name="password" type="password" style="width: 150px" /><br><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="submit" value="Submit" name="cmdSubmit" />
</form>
 
	
	
	
 
 
 
</body>
 
</html>

Open in new window

0
Comment
Question by:dhalliday
  • 2
4 Comments
 
LVL 14

Accepted Solution

by:
rejoinder earned 500 total points
ID: 24378682
I have modified your script just a little.  There seemed to be a constant missing "ADS_SERVER_BIND".  After making a change to the line and to the contstants, I can use the script to pass my credentials and get feedback.
<script language="vbscript">
 
'==============================================================================
'Author:		David Halliday
'Date:			11/6/2008
'Script Name:		Auth.hta
'Purpose:		This page is a compilation of functions that run in 
'			an HTML Application (HTA).  This page will authenticate an 
'			Administrator account that resides in the Active Directory 
'			path: "<InsertLDAPPath>" and allow them 
'			to continue on to the SCCM.hta file to create the necessary
'			accounts.
'
'Included Functions (w/ Description):
'Primary Functions
'	cmdSubmit_OnClick(): Function used to parse the provided user information
'		to the Authentication Function when the Submit button is clicked on
'		the page.
'	Authenticate(): Main script used to authenticate the user information 
'		with Active Directory. This will also log the Administrator 
'		information if the authentication is successful or if it fails.
'
'==============================================================================
 
Function setSize()
    window.resizeTo 375,200
End Function
 
Function cmdSubmit_OnClick()
    '==============================================================================
    'Name:			cmdSubmit
    'Description:		Function used to parse the provided user information
    '		to the Authentication Function when the Submit button is clicked on
    '		the page.
    'Passed Variables:	strAdmin, strPW
    'Output Variables:	strAdmin, strPW
    '==============================================================================
 
    Dim strAdmin		'Administrator's User Name variable
    Dim strPW 			'Administrator's Password variable
    					    
    if auth.username.value = "" Then
       msgbox ("ERROR: No admin account information provided. Please Try Again!")
       cmdSubmit_OnClick = False
    Elseif auth.password.value = "" Then
        msgbox ("ERROR: No admin account information provided. Please Try Again!")
        cmdSubmit_OnClick= False
    Else
        strAdmin = auth.username.value
        strPW = auth.password.value
    End If
    Authenticate strAdmin, strPW
    'window.close()
End Function
 
Public Sub Authenticate (Byref strAdmin, Byref strPW)
    '==============================================================================
    'Name:			Authenticate
    'Description:		Main script used to authenticate the user information 
    '		with Active Directory. This will also log the Administrator 
    '		information to a specified directory and file if the authentication is 
    '		successful or if it fails.
    'Passed Variables:	strAdmin, strPW, dirLog, strALog
    'Output Variables:	strAdmin
    '==============================================================================
    
    On Error Resume Next
    
    Const ADS_SECURE_AUTHENTICATION = &H1
    Const ADS_SERVER_BIND = &H200
    
    Dim strPath			'LDAP path where the Administrator accounts are listed
    Dim LDAP 			'Directory Service Object reference variable
    Dim strAuth			'Parses the User Name and Password through the DSObject
    
    strPath = "LDAP://<Insert Proper LDAP Path>"
    
    Set LDAP = GetObject("LDAP:")
    Set strAuth = LDAP.OpenDSObject(strPath, strAdmin, strPW, ADS_SECURE_AUTHENTICATION Or ADS_SERVER_BIND)
    If Err.number <> 0 Then
        intTemp = msgbox(strAdmin & " could not be authenticated", vbYES)
        if intTemp = vbYes Then
            window.location.reload()
        End If
    Else
        For Each obj in strAuth
            If obj.Class = "user" Then
                If obj.Get("samAccountName") = strAdmin Then
                    msgbox ("Success! " & strAdmin & " has been authenticated with Active Directory")
                    Set objShell = CreateObject("Wscript.shell")
                    objShell.run ("mshta.exe c:\sccm.hta")
                End If
            End If
        Next
    End If
End Sub
 
</script>
 
<body onload="vbs:setSize()">
<div class="style2">
	<h3>Administrator Authentication</h3> 
</div>
<form method="post" id="auth" name="auth">
	<span class="style3"><strong>User Name:&nbsp; </strong></span> 
	<input id="username" name="username" type="text" style="width: 150px" /><br>
	<span class="style3">
	<strong>Password:&nbsp;&nbsp;&nbsp;&nbsp;    </strong></span> 
	<input id="password" name="password" type="password" style="width: 150px" /><br><br>
	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
	<input type="submit" value="Submit" name="cmdSubmit" />
</form>
</body>
</html>

Open in new window

0
 

Author Comment

by:dhalliday
ID: 24386121
That seems to work, but with the LDAP string am I able to do:

strPath = "LDAP://ou=users,ou=it,dc=mydomain,dc=com"

or do i have to use:

strPath = "LDAP://mydomain.com/rootDSE"

I am trying not to search all of AD for this information as I only want the people in the specific OU to be able to authenticate.

Thanks,

-D
0
 
LVL 14

Expert Comment

by:rejoinder
ID: 24389036
Use this;
strPath = "LDAP://ou=users,ou=it,dc=mydomain,dc=com"
That will focus the search to that OU (and sub-OU's) only.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

786 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question