Solved Display asterisk for user input in CMD

August 27, 2013 at 09:54:34
Specs: Windows XP, pentium 4 3.00Ghz. 1gb ram
How to make 1234(password) in the following batch code to display * (asterisk)?

title FolderLock Program
if EXIST "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" goto UNLOCK
if NOT EXIST MyFolder goto MDMyFolder
goto LOCK
ren MyFolder "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
attrib +h +s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
echo Folder locked
exit cmd.exe
echo Enter password to Unlock Secure Folder
set/p "pass=>"
if NOT %pass%== 1234 goto FAIL
attrib -h -s "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}"
ren "Control Panel.{21EC2020-3AEA-1069-A2DD-08002B30309D}" MyFolder
echo Folder Unlocked successfully
exit cmd.exe
echo Invalid password
exit cmd.exe
md MyFolder
echo MyFolder created successfully
exit cmd.exe

See More: Display asterisk for user input in CMD

Report •

August 27, 2013 at 10:20:59
It is not possible to do this with a batch file alone. I just did a quick google search and found the following...

Be sure to check out a few of the links Google brings back for you.

Law of Logical Argument: Anything is possible if you don't know what you're talking about.

Report •

August 27, 2013 at 21:01:49
✔ Best Answer
Well, there kind of is a way, but it is somewhat convoluted. Here is prototype:
::========= begin batchscript
@ECHO OFF & setlocal enabledelayedexpansion
set bksp=
set esc=
set asc=%esc%%bksp%0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_
:: set maximum length of passwd:
set pattern=8
for %%z in (%pattern%) do call :getset %%z
echo qq:%qq%
goto :eof

set /a c+=1
choice /c:%asc% /n>nul
set /a xx=!errorlevel!
:: ENTER / TAB can't be used to end input, ESC is arguably the next best choice
if !xx! lss 2 goto :eof
if %xx% equ 2 (
set qq=!qq:~0,-1!
set /p = <nul
set /a c-=1
goto :getset
call :yy
set qq=!qq!!xx!
set /p =*<nul
if %c% equ %1 goto :eof
goto :getset

goto :eof

set /a xx-=1
set xx=!asc:~%xx%,1!
::========= end batch

lines 2 and 3 vars (ESC, BKSP) must be set literally to their respective values (27, 8).
Let me know if you don't know how to do this, if you want to use this.

Counterintuitively, ESC ends input, not ENTER, due to CHOICE constraints. You should warn the USER ahead of time of this caveat.

Here's a basic method for appending strings without linefeeds using batch:
::========== begin demo

@echo off & setlocal
::demo append without linefeed
set x=
set /p x=data:
if not defined x goto :eof
if "%x%" equ " " (
>>app echo.
) else (
set /p =%x%<nul>>app
goto :nexline
::=========== end demo/batch
note that a solitary space followed by ENTER will move to the next line, otherwise it gets glued together onto the same line.

message edited by nbrane

Report •

August 28, 2013 at 22:20:34
Thanks Newbie10 and nbrane for your response. Actually i have zero knowledge about batch and its coding. Hence, i could not implement any of your suggestions. The code i posted above were found through Google. I am thinking to have: if my choice is 1 then display * on screen, if my choice is 2 then again display *, so for choice of 3 and 4.

Isn't it possible?

Report •

Related Solutions

August 29, 2013 at 00:42:25
Hello Nabam,

Have a look at this;


Happy is ONE who says I am an OttoMAN.

Report •

Ask Question