Mask password with Asterisk

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Message
Author
IcarusLives
Posts: 175
Joined: 17 Jan 2016 23:55

Re: Mask password with Asterisk

#16 Post by IcarusLives » 03 May 2024 08:27

This is probably what you're looking for.

I cannot recall where I found this code. Sorry about that.

Code: Select all

@echo off
   
call :getPassword password 

echo Password:%password%
pause
exit /b


rem Subroutine to get the password
:getPassword returnVar
set "_password="
for /f %%a in ('"prompt;$H&for %%b in (0) do rem"') do set "BS=%%a"

set /p "=Password:" <nul 

:keyLoop
set "key="
for /f "delims=" %%a in ('xcopy /l /w "%~f0" "%~f0" 2^>nul') do if not defined key set "key=%%a"
set "key=%key:~-1%"

if defined key (
    if "%key%"=="%BS%" (
        if defined _password (
            set "_password=%_password:~0,-1%"
            setlocal enabledelayedexpansion & set /p "=!BS! !BS!"<nul & endlocal
        )
    ) else (
        set "_password=%_password%%key%"
        set /p "=*"<nul
    )
    goto :keyLoop
)
echo.
if defined _password ( set "exitCode=0" ) else ( set "exitCode=1" )
endlocal & set "%~1=%_password%" & exit /b %exitCode%

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Mask password with Asterisk

#17 Post by SIMMS7400 » 04 May 2024 11:41

Paste doesn't work on that piece of code either

Post Reply