HOME
Stephen Knight
10/20/2009
09:36 AM
Password entry obscured from batch file
Type:
VBScript, Batch/Command file
Category:
Password
These scripts show some ways of prompting for a hidden password within a batch file so that it can be returrned in a variable for authenticating with other commands, e.g. as part of creating an automated FTP script requiring the user to enter their password rather than incorporate it in the script.
This script is a variation on the one below which I have been using for a while to obscure output using built in commands to change console colour etc. This goes one further and sets the foreground and background colours to completely hide the text which is not possible using the built in command. This makes the script XP only though without pre-creating a .REG file to import using REGEDIT as Window 2000 and before did not have the REG.EXE command. There is a version in the code section below which creates a .REG file on the fly.
http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/Q_24713227.html?cid=1135#a25277510
There is also a matching non-obscured username prompting box here:
Code
Explanation
Examples
Example script to prompt for password and then use that in a FTP script to upload a file to an ftp server. This picks up the users current windows user name, prompts them for a password and copies a file from their c:\ to a directory based on their username:
@echo off
call :getpassword
if [%pwd%]==[] echo No password entered, exiting script & exit /b
(echo open 110.110.110.110
echo user %username%
echo %pwd%
echo md /backups/%username%
echo cd /backups/%username%
echo bin
echo put "C:\backup.bkf"
echo quit
) | ftp -n -i
exit /b
:getpassword
set InputTitle=Enter Password:
set InputResult=%Temp%\Input.tmp
REM add registry entry
set reg="%temp%\regpw.reg"
(echo Windows Registry Editor Version 5.00
echo [HKEY_CURRENT_USER\Console\Enter Password:]
echo "CursorSize"=dword:00000064
echo "FaceName"="Terminal"
echo "FontFamily"=dword:00000030
echo "FontSize"=dword:0010000c
echo "FontWeight"=dword:00000190
echo "ScreenBufferSize"=dword:0003001e
echo "ScreenColors"=dword:00000088
echo "WindowPosition"=dword:017c01e0
echo "WindowSize"=dword:0003001e) > %reg%
regedit -s %reg%
start "%InputTitle%" /wait "%ComSpec%" /v:on /c "echo.&set /p Input= &echo !Input!>"%InputResult%""
for /f "delims=" %%a in ('type "%InputResult%"') do set pwd=%%a
del "%InputResult%"
REM Remove registry entry
set reg="%temp%\regpw.reg"
(echo Windows Registry Editor Version 5.00
echo [-HKEY_CURRENT_USER\Console\Enter Password:])>%reg%
regedit -s %reg%
exit /b
Attachments