Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Requesting user input for password - display *'s not text 3

Status
Not open for further replies.

djhawthorn

Technical User
Mar 4, 2002
641
AU
I need (or would like) to put up a request for user input in my script, similar to using inputBox(), only to ask for a password where the text that would show on the screen are *'s, not the actual text. (So the text is hidden from the screen, but not the script).

Is this possible?
If so, what code achieves it?

[auto] MCSE NT4/W2K
 
I don't think you can using VBscript, it's waiting for the user to hit enter in the inputbox(), the only way I can see doing it is with a web page, although I could be mistaken.
 
I have just run up on this as well. Looking for any updates on this topic.

In VB, the inputbox function has a property called passwordch which can be anything you choose (but is usually the *). I have not been able to set that property in VBscript, but then again I have been a VBScript author for exactly 35 minutes now.

Appreciate any replies. Thanks.
 
I have run across this issue as well. I have found that if you use wscript to run your scripts this is almost impossible without creating your own COM object to access the Password API in windows. But there is hope!!!

If you use cscript instead you can use the built in function for vbscript to mask a password, but it doesn't show *'s. It just doesn't show anything, but the password is passed to the script.

Here is a link explaining.


Bob Wells is one of the MS Scripting Guys, he would be the one to know.

Enjoy---Z
 
I've used the above for a password prompt via vbs in winpe.
Worked really well, just remember to register the ocx first! :)



-------------------------
objUSER = "metalremains"
 
Sorry metalremains,

I should have clarified. If you have a WinXP machine this is already built in, there is no need to register the .ocx.
XP uses the scriptpw.dll which is already registered with WSH.

But if you use Win 9x, 2000,ME(God forbid).
Then metalremains is absolutely right. You would have to register the appropriate files.

Sorry about that.

Z
 
I actually found a 2rd party solution, called vbsinput.dll (or .ocx or something) - it allows custom input boxes allowing for password inputs, numeric inputs, and other stuff.

If you need a copy, let me know and I'll post it up. Only problem is, you need to have it installed and registered on the machine to use it.

[auto] MCSE NT4/W2K
 
Thanks markdmac, this is exactly what I was looking for in a solution.

I feel much better about it now.
 
This again...
always saying it can't be done.
never believe anything
<body onload=&quot;askForPass()&quot;>
<script language=&quot;vbscript&quot;>
Function askForPass()
Dim Ask
Ask = inputBox(&quot;enter your Login Name:&quot;)
Login =(&quot;Apple&quot;)
If Ask=Login Then
set Ask = nothing
Ask = inputBox(&quot;Enter Your Password:&quot;)
Pass =(&quot;Orange&quot;)
if Ask =Pass Then
Set Ask = nothing
end if
elseif MsgBox(&quot;Wrong User name&quot;) Then
location.reload(true)
end If
End function
</script>[pipe]
<!-- Insert HTML here -->
</body>
 
Hey Phalanx1,

You're talking with a newbie here. Looks like your script is to be run in a browser. Probably not the most efficient method for me just wanting to map network drives. However, I am intrigued by this line:

Function askForPass()

This function (askForPass) is not listed in the VBscript documentation. Perhaps you can explain it to us if it does not take more than a paragraph or two.

Thanks!
 
kidvegas,
The function AskForPass() is defined in the code Phalanx1 provided, which is why it's not to be found in the VB documentation. He defined the function (starting with the line you indicated above, ending with
Code:
End function
, and indicated that it should be called when the page is loaded with the following line of code:
Code:
<body onload=&quot;askForPass()&quot;>
 
I see (I think). A person can define their own functions. This one happened to be named askForPass(). It could've been passPlease() or anything. The reason to code this function is that it can then be called numerous times if needed without redefining it, correct?

To show my newbie colors, it took me 15 minutes to get the code to work, as I was excited to try this out. Unless I have done something terribly wrong, the code is functional but misses the point. One only gets the message box error if they mess up the the login. (Apples works, apples doesn't). The password has no bearing. You can enter anything there and the code goes to completion. Still, when entering the password during the Ask = inputBox(&quot;Enter Your Password:&quot;) displays what is typed in clear text. The solution we were looking for is to disguise what is typed with ***.

So my next question is: VBS is VBS right? A function such as inputbox() has the same properties in a notepad script as it does in an HTML page, or are there more properties available in an HTML page?
 
kidvegas,
Regarding functions, that's correct - it could be called anything, and you code it so you can call it multiple times without recoding it.

Regarding printing *'s: You're right there, too. I meant to point out earlier that it didn't address the original issue but got caught up in the explanation of functions instead. To get the *'s to print, I suggest using the (non-VBS) solutions given by zmann, dhawthorn, metalremains & markdmac.
 
The way I usually do it is using IE to handle the input. Not actually run the code in IE, just use IE itself to process the input. Here's an example snippet from one of my scripts which uses IE to gather user input:
---------------------------------------------------
Set IEX = CreateObject(&quot;InternetExplorer.Application&quot;)
IEX.Height = 300
IEX.Width = 450
IEX.MenuBar = 0
IEX.ToolBar = 0
IEX.StatusBar = 0
IEX.Navigate ToolPath & &quot;\form.htm&quot;
IEX.Visible = 1
Set IE = IEX.Document
Do
Loop While (IE.script.CheckVal()=0)
If err <> 0 or IE.script.CheckVal() <> 1 Then
IEX.Quit
Set IEX = Nothing
Set IE = Nothing
GetData = false
else
CurrentSystem = IE.Data.System.Value
IEX.Quit
Set IEX = Nothing
Set IE = Nothing
end if
---------------------------------------------------
Here is the form.htm that it calls:

<HTML>
<script language=vbscript>
Sub Window_OnLoad()
Data.System.Focus()
ready = 0
End Sub

Sub SubmitIt_OnClick
if data.system.value = &quot;&quot; then
msgbox &quot;You cannot have a blank system name!&quot;
else
ready = 1
end if
End Sub

Public Function CheckVal ()
CheckVal = ready
End function
</script>
<form name=data>
System: <input type=text name=system><BR><BR>
<input type=button name=submitit value='OK'>
<input type=button name=cancel value='Cancel' onclick=&quot;vbscript:ready=2&quot;>
---------------------------------------------------
As you can see, it instantiates an IE object and the IE object loads the form.htm. It then loops while the public CheckVal function is returning a 0. Checkval returns the value of the ready var which is initialized as 0 at page load. When the form is ready to be processed, I set ready to 1 which kills the loop. If it is cancelled, I set ready to 2. Ready is evaluated after the loop and if it's not 1 it assumes cancel. It looks involved, but I just keep it in a template file and when I need complicated input I find it works excellent, especially since almost all Win boxes have IE. TO get the data from the form, you then use IEObject.HTMLFormName.HTMLElementName.Value.

This rocks because you can make pretty looking and fancy input windows for VBS scripts.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top