windowsbatch-filepasswordscmd

What would be the Windows batch equivalent for HTML's input type="password"?


I need to get authentication credentials from the users within a Windows script but the classic "first Google result" approach:

SET /P USR=Username: 
SET /P PWD=Password: 

is less than satisfying, so I was wondering if there's let's say an "equivalent" to HTML's input type="password"?


Solution

  • check out this

    http://www.netikka.net/tsneti/info/tscmd052.htm

    @echo off & setlocal enableextensions
        :: Build a Visual Basic Script
        set vbs_=%temp%\tmp$$$.vbs
        set skip=
        findstr "'%skip%VBS" "%~f0" > "%vbs_%"
        ::
        :: Prompting without linefeed as in Item #15
        echo.|set /p="Password: "
    
        :: Run the script with Microsoft Windows Script Host Version 5.6
        for /f "tokens=* delims=" %%a in ('cscript //nologo "%vbs_%"') do set MyPass1=%%a
    
        ::
        ::echo.
        echo.|set /p="Retype  : "
    
        for /f "tokens=* delims=" %%a in ('cscript //nologo "%vbs_%"') do set MyPass2=%%a
        ::
    
        :: Clean up
        for %%f in ("%vbs_%") do if exist %%f del %%f
        ::
        :: Demonstrate the result
        echo.
        if "%MyPass1%"=="%MyPass2%" (
          echo The entered password was %MyPass1%
          ) else (
          echo No match)
        endlocal & goto :EOF
        '
        'The Visual Basic Script
        Set WshPass = WScript.CreateObject("ScriptPW.Password") 'VBS
        Password=WshPass.GetPassWord() 'VBS
        WScript.Echo PassWord 'VBS