Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I've created a batchfile that asks for a password to connect to an ftp with. This batch works perfectly all except for the fact that the password is visible when its typed in. Thus sharing it with everyone who can see the screen its on.
My question is; How do you hide user input in a batch file or even better. How do you show a * instead of the characters typed in. So you'll see '******' i.s.o. 'password'.

There's no way to achieve exactly what you wish under Windows XP/2K using batch facilities only.
A workaround is to set the background and text colors quite similar and restore them after typing the password, e.g.
Color 01
Statements to enter the password...
ColorTo choose the preferred combination type Color /? and try to play.

This batch creates a util called input.com which it then uses to redirect input to file, set the password in a var called pw.
::== pwINPUT.bat
@echo offcall :make-it
echo pw ?
input>pw.txt
set /p pw=<pw.txt
type nul > pw.txt
del pw.txt
goto :eof:make-it
> #.d echo E0100 B4 08 CD 21 88 C2 B4 02 CD 21 80 FA 0D 75 F1 B4
>> #.d echo E0110 4C CD 21 5B 2B D2 AC 3C
>> #.d echo N input.com
>> #.d echo RCX
>> #.d echo 0018
>> #.d echo W
>> #.d echo Q
debug < #.d > nul
del #.d
goto :eof
:: DONEAs IVO says, not much way to do it in plain NT.
Thanks to dtech10 for the nifty util.
=====================================
If at first you don't succeed, you're about average.M2Go

IVO:
The color trick doesnt seem to work. At least not two the same colors which would hide the whole shebang.
Mechanix2Go:
It looks like it does what I want it too, but where does it dump the password? It doesnt have to be secure, just as long as it hides the input.

"This batch creates a util called input.com which it then uses to redirect input to file, set the password in a var called pw."
If at first you don't succeed, you're about average.M2

The Color trick is just a workaround as background and text can't be set to the same value (reported by the help).
I suggested to choose a pair of colors that make hard to view what you are typing if not just close to the screen. Color 01 may work in that way, but you have to issue a ClS just before restoring the default settings as Color affects ALL the window look not just the rows typed after it is set.
The sequence I suggest is
Echo Enter password
Color 01
Set /P PSW=
ClS
Colorwhere Color mn is at your choice

IVO:
Yea thats what I noticed too, thanks.
Mechanix2Go:
How do I get the pass out again? When I echo the %pw% it doesnt show me anything. Might have to do with the fact that it gives an error saying #.d cant be opened, cause its in use.

Hi blink,
Are you running the batch at a CMD prompt?
NOT in a "run box".
If at first you don't succeed, you're about average.M2

M2: I put it all in a batch file which I opened. Thats also the way I ultimately want to implement it.

![]() |
Explorer Problem
|
Black screen freeze befor...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |