Solved

Issues with Active Directory authentication through VBScript in an HTA

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Restoring deleted objects in Active Directory has been a standard feature in Active Directory for many years, yet some admins may not know what is available.
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…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now