0

Pretty straight forward question. Is it possible to shadow-type in cmd? ( I mean typing in the cmd window without it showing what you've typed ) Like when you're setting a password for a user with net user J.Doe * for example. Is it possible to immitate that with commands?

iNT
  • 3
  • 1
  • cmd doesn't have a built-in command for that, but you can write an external console program to do a raw read without echoing user input to the screen buffer. For example, in Python you can read a character without echo via `msvcrt.getwch`. You lose the convenience of the console's cooked read (e.g. input history via F3/F7 and up/down arrows; aliases; and command-line editing with left/right arrow keys, home, end, backspace, etc). You'll have to implement those features yourself. – Eryk Sun Jun 18 '17 at 18:02
  • if you want to hide your input check this: https://stackoverflow.com/a/24396213/388389 – npocmaka Jun 18 '17 at 18:21
  • 1
    Possible duplicate of [Hide Input in Batch File](https://stackoverflow.com/questions/5852759/hide-input-in-batch-file) – Eryk Sun Jun 18 '17 at 18:51

1 Answers1

0

A 100% Batch solution i made, which accept backspace to remove a char, accept the enter key to valid the password and automatically count the password length.

@echo off&cls

::The password
set "$Mdp=toto1234"

::La longeur du Mot de passe
set "$Long=-1"
for /F "delims=" %%c in ('cmd /D /U /C echo %$Mdp% ^| find /V ""') do (set /a $Long+=1)

::Les autres variables
set "$l="
set "$l1="
set "$C=0"

:test
if %$c%==%$Long% goto:Pastrouve
set "$T="
cls&echo Entrer votre MDP : %$l1%
For /F "delims=" %%# In ('Xcopy /W "%~f0" "%~f0" 2^>Nul') Do If Not Defined $T Set "$T=%%#"

set "$testenter=%$T:~-1%"
if not defined $Testenter goto:Pastrouve

if %$T:~-1%== (
 if not %$C%==0 (
  Set "$l=%$l:~0,-1%"
  set "$l1=%$l1:~0,-1%"
  set /a $C-=1)
 ) else (
  Set "$l=%$l%%$T:~-1%"
  set "$l1=%$l1%*"
  set /a $C+=1)

if "%$l%"=="%$Mdp%" goto:trouve
goto:test

:trouve
echo Pass OK 
Pause >NUL & exit/b

:Pastrouve
echo PASS NOT OK
Pause>NUL & exit/b

And the same using BAT/Powershell

@echo off&cls
set $MDP=toto1234
for /f "delims=" %%a in ('powershell -c "$rep=read-host Entrer_votre_MDP -AsSecureString;$password = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($rep));write $password"') do set $rep=%%a

if %$MDP%==%$rep% (echo PASS OK) else (echo PASS NOT OK)
exit/b
SachaDee
  • 9,245
  • 3
  • 23
  • 33
  • FYI, xcopy.exe is an external program (unlike `copy`), so it's not 100% batch, but Windows should always have this program. This depends on unusual behavior. xcopy.exe does a raw console read for the "press any key" prompt by calling `SetConsoleMode` to clear out the `ENABLE_PROCESSED_INPUT`, `ENABLE_LINE_INPUT`, and `ENABLE_ECHO_INPUT` flags. Then, unlike most programs that wait for the user to press a key, it actually writes the entered character back to `StandardOutput`, which in this case is the pipe for the `for /f` loop. – Eryk Sun Jun 19 '17 at 21:35