Solved Hide input - Batch file

Hewlett-packard / Pavilion hpe
April 18, 2015 at 09:36:20
Specs: Windows 7 Professional x64, 3.6GHz 16GB
Allright. I have a batch file where the user is authenicated with a username and a password. When the password is typed in, everyone that sees the screen is able to read the password.

I've read in other forums that replacing the letters with asterisks is a tricky thing so I'm not going to ask for how to do that here. Instead I'd like to ask; Is there a way of hiding the input entirely? Like it's done in the terminal in Linux (Like when you enter the password for the superuser when executing sudo commands).

I do not know if this is possible, or if it'll work the same way as with asterisks.

99 little bugs in the code,
99 little bugs.
Take one down, patch it around,
129 little bugs in the code.

See More: Hide input - Batch file

Report •

April 18, 2015 at 19:21:47
✔ Best Answer
Nah, not with pure batch as far as I know. CHOICE can be fudged somewhat, but it's really sucky because you can't use {ENTER} to end the input. Maybe vbscript/jscript or vis.basic, or some third-party app. I've used DEBUG to make a small routine that works like CHOICE, but it is probably not up to 64-bit OS'.

@goto :aaa
e100 b4 07 cd 21 b4 4c cd 21
:: is a simple key-stroke gatherer. Like CHOICE, it returns errorlevel
:: but based on input-key ascii-value instead of location in string.
if exist goto :bbb
debug<%~dpn0.bat >nul 2>nul

@echo off & setlocal enabledelayedexpansion
set strg=
:: foll. line needs to be tweaked for your requirements
:: use CAR-RET for exit, could also test for TAB or LF at this point
:: now convert keystroke from ascii to alpha-num using the string and offset
set /a dd=%errorlevel%
:: offset DD to match the string ALPHA
set /a dd-=65
SET K=!ALPHA:~%dd%,1!
::==== end batch
Then you still got to account for the nefarious user's BACKSPACE! If you're still interested, I'll help with that, but not wasting time on it at this point.

Report •
Related Solutions

Ask Question