Computing.Net > Forums > Programming > Hiding user input in a Batch File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Hiding user input in a Batch File

Reply to Message Icon

Name: vortech
Date: November 13, 2007 at 05:55:34 Pacific
OS: Windows XP SP2
CPU/Ram: 1 GIG
Product: HP/D530
Comment:

I have a batch file that prompts the user for a password, which I then store as a variable to be used later. Is there anyway to hide the text while it's being typed on the screen to keep other people from visually seeing what the user is entering.

I thought of changing the background color and text color to the same, but Windows XP won't let you.

Any ideas would be appreciated!



Sponsored Link
Ads by Google

Response Number 1
Name: klint
Date: November 13, 2007 at 10:07:16 Pacific
Reply:

I don't know if you can do it directly using just cmd.exe's internal commands. For example, the SET /P command echoes the password back. Does anyone know of a way? In the meantime, here's a technique that uses a one-line VBScript program.

Paste the following line into a new file called GetPassword.vbs:

wscript.echo CreateObject("ScriptPW.Password").GetPassword()

Then use it from your batch file as follows:

for /f "tokens=*" %p in ('cscript /nologo GetPassword.vbs') do set password=%p

I hope that helps.

However, be careful. There are security risks when doing user input. For example, suppose you try to create a file full of passwords, by appending a user's password to it:

for /f "tokens=*" %p in ('cscript /nologo GetPassword.vbs') do set password=%p
echo %password% >> pwdfile.txt

Now the user could enter something like
"xx && del \WINDOWS\system32\ImportantFile.exe" as his password (Where "ImportantFile.exe" is any file that you don't want to lose.) This can cause your 'echo' command above to trash your system.


0

Response Number 2
Name: tonysathre
Date: November 13, 2007 at 10:19:28 Pacific
Reply:

You can use conset.exe with the /ph switch. When used, typed text will no be echoed back to STDOUT.

"Computer security." — Oxymoron


0

Response Number 3
Name: vortech
Date: November 14, 2007 at 12:39:16 Pacific
Reply:

klint and tony,

thank you both for your suggestions!


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More







Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: Hiding user input in a Batch File

using a text input in a batch file www.computing.net/answers/programming/using-a-text-input-in-a-batch-file/12980.html

Extract comp. alias in a batch file www.computing.net/answers/programming/extract-comp-alias-in-a-batch-file/11253.html

Get a Folder size in a batch file www.computing.net/answers/programming/get-a-folder-size-in-a-batch-file/9587.html