More Windows Scripting Workarounds from Nilpo - Masking Passwords without ScriptPW
(Page 3 of 4 )
Masking Passwords without ScriptPW
Okay, so using ScriptPW isn't technically a workaround, although it is a little-known scripting secret. But, what happens if you're not on a machine running Windows XP or Server 2003 and don't have access to the scriptpw.dll file?
I'm glad you asked. That will allow me to introduce a workaround.
This workaround makes use of HTML's form inputs. As you may know, HTML has a form input element specifically for receiving passwords. It's a specialized input box that employs password masking. The example in this script works with an HTML page and reads the values from the HTML form.
The code in this workaround is slightly complex. I want you to see the code in its entirety first, then I'll explain the key parts. To begin, let's look at the HTML page required.
<html>
<head>
<title>Please Enter Your Password</title>
<script language="VBScript"><!--
Sub RunScript
OKClicked.Value = "OK"
End Sub
Sub CancelScript
OKClicked.Value = "Cancelled"
End Sub
// --></script>
</head>
<body>
<font size="2" face="Arial">Password: </font>
<font face="Arial">
<input type="password" name="UserPassword" size="40"></font>
<p>
<input type="hidden" name="OKClicked" size = "20">
<input id="runbutton" class="button" type="button" value=" OK " name="ok_button"
onClick="RunScript">
<input id="runbutton" class="button" type="button" value="Cancel" name="cancel_button"
onClick="CancelScript">
</body>
</html>
This HTML page has two crucial parts: the first is the HTML form and the second is a VBScript in the HEAD section of the document.
This example does use VBScript, therefore it will need to be run in Internet Explorer.
The basics of this HTML form aren't important. What is important is the use of the password input box and the id that has been given to it. Notice also that there are two buttons. One is used to "submit" the form; the other is used to cancel submission. You should also notice that both have the same id. While having two elements with the same id is a violation of coding standards, it does provide us with a quick and dirty method of passing two possible values to our script without needing to check two different elements.
Next: More on Password Masking without ScriptPW >>
More Windows Scripting Articles
More By Nilpo