How to hide batch input (password)

Asked

Viewed 256 times

-4

How can I hide the password from entering/entering the batch when it runs?

Because every time I run it appears the password when I type, to avoid being seen by someone.

cls
@echo off
title Folder Cofre

if exist "Control Panel.{21ec2020-3aea-1069-a2dd-08002b30309d}" goto unlock
if not exist Cofre goto mdcofre

:confirm
echo Pretende bloquear a sua pasta (s/n)
set/p "cho=>"

if %cho%==s goto lock
if %cho%==s goto lock
if %cho%==n goto end
if %cho%==n goto end

echo Escolha inválida.
goto confirm

:lock
ren cofre "Control Panel.{21ec2020-3aea-1069-a2dd-08002b30309d}"
attrib +h +s "Control Panel.{21ec2020-3aea-1069-a2dd-08002b30309d}"

echo Pasta bloqueada
goto end

:unlock
echo Digite a senha para desbloquear a pasta
set/p "pass=>"

if not %pass%==123456 goto fail

attrib -h -s "Control Panel.{21ec2020-3aea-1069-a2dd-08002b30309d}"
ren "Control Panel.{21ec2020-3aea-1069-a2dd-08002b30309d}" Cofre

echo Pasta desbloqueada com sucesso
goto end

:fail
echo Senha inválida
goto end

:mdcofre
md Cofre
echo Cofre criado com sucesso
goto end

:end

1 answer

1

@echo off && setlocal enabledelayedexpansion

<con: cd /d "%~dp0" & color 0a && mode 60,8
title<nul & title Folder Lock/unLock Script && >nul chcp 65001
set "_crtl_panel=control panel.{21ec2020-3aea-1069-a2dd-08002b30309d}"

Certutil -decode -f "%~f0" "%temp%\2L.bin" >nul 2>&1 && goto:next || goto:fail
:: < -----BEGIN 2L.bin----- G1sxRhtbMEobWzFGG1swSg0K -----END 2L.bin----- > ::

:next
if exist "!_crtl_panel!" (goto=:unlock)else if exist Cofre (
     goto=:confirm) else goto=:mdCofre 
   
:confirm
echo\ & set /p _yn=Pretende Bloquear Sua Pasta [s/n]: 

if /i "!_yn!"=="s" (goto=:lock) else if /i "!_yn!"=="n" (
     endlocal && goto=:EOF)else echo\Escolha inválida.
     
timeout -1 & cls & set "_yn=" & goto=:confirm  

:lock
<con: rename .\Cofre "!_crtl_panel!" && attrib +h +s "!_crtl_panel!"
dir/a:d "!_crtl_panel!" >nul && echo\Pasta Bloqueada && timeout -1 && goto=:EOF

echo\Erro ao Bloquear Pasta...& timeout -1 & endlocal && goto=:EOF

:unlock
echo\ & set /p "=_" < nul > "Digite a Senha Para Desbloquear Pasta "
findstr /A:1E /V "^$" "Digite a Senha Para Desbloquear Pasta " nul >con

del "Digite a Senha Para Desbloquear Pasta " && set /P "_pass="
color 0a & type "%temp%\2l.bin" & >nul 2>&1 del/q /f "%temp%\2l.bin"

for %%i in (reinstall,"listsize=0","listsize=50")do doskey.exe /%%~i

if !_pass! equ 123456 2>nul (
     attrib -h -s ".\!_crtl_panel!"
     rename  ".\!_crtl_panel!" Cofre 
     dir/a:d Cofre >nul && echo\Pasta Desbloqueada Com Sucesso
     goto=:EOF)else Echo\Acesso Negado && goto=:fail

:fail
echo\ & echo\Senha inválida && timeout -1 & goto=:EOF

:mdCofre
echo\ && mkdir Cofre && echo\Cofre Criado Com Sucesso && endlocal && goto:eof

inserir a descrição da imagem aqui


  • To mask an input into a bat, you can use the solution of @Aacini in this reply, where a findstr is used interchangeably with a set /p already omitting input/password entry:

    set /p "=_" < nul > "Digite a Senha Para Desbloquear Pasta "
    findstr /A:1E /V "^$" "Digite a Senha Para Desbloquear Pasta " nul >con
    
    del "Digite a Senha Para Desbloquear Pasta " && set /P "_pass="
  • To delete/remove the line typed in the input/password, this solution @Lotpings in this reply // with an adaptation suggesting the use of Base64

    Certutil -decode -f "%~f0" "%temp%\2L.bin" >nul 2>&1 && goto:next || goto:fail
    :: < -----BEGIN 2L.bin----- G1sxRhtbMEobWzFGG1swSg0K -----END 2L.bin----- > ::

  • Obs.: Content that is decoded in Base64 in this bat/cmd results in the file "%temp%\2l.bin":

inserir a descrição da imagem aqui


  • To clear/remove command histories typed in line(s) of Doskey buffers/history, and thus preventing them from appearing when pressed keys , , F1, F3, F7, F9 and so on. , you can use a @It Wasn’t Me in this reply, where Doskey is reinstalled and a value of 0 to 50 is reserved, thus erasing the content previously stored in the transitory memories of Doskey.

    for %%i in (reinstall,"listsize=0","listsize=50")do doskey.exe /%%~i


Some additional readings:

[√] Doskey

[√] Findstr

[√] Goto :Label

[√] Escape Characters

[√] Ansi Escape Codes

[√] Conditional Execution || && ...

[√] Base64 Encode or Decode (Macos/Windows/Linux)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.