Solved

Issues with Active Directory authentication through VBScript in an HTA

Posted on 2009-05-12
4
3,128 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
In-place Upgrading Dirsync to Azure AD Connect
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…

840 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