Batch File with Hide Password

Hello,

i have batch file with emddebed user name , now i want to create for each user a dedicated user name and password, so i want batch file that ask for user name and password should not be clear , check below my batch


get.bat

echo del c:\ftp\get.out
echo cd c:\ftp
ftp -v -n < c:\ftp\get.ftp > c:\ftp\get.out
exit

Open in new window





get.ftp
o 10.10.100.123
USER user1
PASSWORD 
ascii
lcd C:\FTP
cd \user\users
get text text.txt
delete text
delete text_temp
quit

Open in new window

LVL 1
palddlAsked:
Who is Participating?
 
Steve KnightConnect With a Mentor IT ConsultancyCommented:
For the password parts of that I have such a script on my site here:

http://scripts.dragon-it.co.uk/links/batch-password2

and another here is useful for hiding a hard coded password in a batch file so it isn't visible unless you know how:

http://scripts.dragon-it.co.uk/links/batch-password1

You can use that along with a dynamically created ftp script, example here:

http://scripts.dragon-it.co.uk/links/batch-ftp-scripting

Would suggest if you need to prompt for username and password (or maybe the username they logon to windows is correct one?) then something like this:

@echo off
call :getusername
if "%user%"=="NONE" (
  echo No username entered
  exit /b
)

call :getpassword
if "%pwd%"=="NONE" (
  echo No password entered
  exit /b
)

echo Username is %user% and password is %pwd%

(echo open 10.10.100.123
echo user %user%
echo %pwd%
echo ascii
echo lcd c:\ftp
echo cd \users\users
echo get text text.txt
echo delete text
echo delete text_temp
echo quit
) | ftp -n -i
pause
exit /b

:getpassword
REM Add getpassword routine of your choice in from first link above. This is for XP onwards.  2000 version in link.
set InputTitle=Enter Password:
set InputResult=%Temp%\Input.tmp
reg add "HKCU\Console\%InputTitle%" /v "CursorSize" /t REG_DWORD /d "100" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "FaceName" /t REG_SZ /d "Terminal" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "FontFamily" /t REG_DWORD /d "48" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "FontSize" /t REG_DWORD /d "1048588" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "FontWeight" /t REG_DWORD /d "400" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "ScreenBufferSize" /t REG_DWORD /d "196638" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "ScreenColors" /t REG_DWORD /d "136" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "WindowPosition" /t REG_DWORD /d "24904160" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "WindowSize" /t REG_DWORD /d "196638" /f >NUL 2>&1
set input=NONE
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%"
reg delete "HKCU\Console\%InputTitle%" /f >NUL 2>&1
exit /b

:getusername
set InputTitle=Enter Username:
set InputResult=%Temp%\Input.tmp
reg add "HKCU\Console\%InputTitle%" /v "ScreenBufferSize" /t REG_DWORD /d "196638" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "ScreenColors" /t REG_DWORD /d "128" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "WindowPosition" /t REG_DWORD /d "24904160" /f >NUL 2>&1
reg add "HKCU\Console\%InputTitle%" /v "WindowSize" /t REG_DWORD /d "196638" /f >NUL 2>&1
set input=NONE
start "%InputTitle%" /wait "%ComSpec%" /v:on /c "echo.&set /p Input= &echo !Input!>"%InputResult%""
for /f "delims=" %%a in ('type "%InputResult%"') do set user=%%a
del "%InputResult%"
reg delete "HKCU\Console\%InputTitle%" /f >NUL 2>&1

exit /b

Let us know if you need help customising!



Steve


0
 
stergiumCommented:
hello.
i've never heard or seen a non plaintext batch file. i dont think that its possible
0
 
palddlAuthor Commented:
ok give also plaintext method
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
Shanmuga SundaramDirector of Software EngineeringCommented:
check whether this helps

the other way is to convert the batch file to exe using a tool that will convert batch file to exe file. there are variety of tools to do this. next password protect the converted exe file. there are tools that will password protect exe file. Some of the googled results here
0
 
QlemoDeveloperCommented:
Do you ask for a script which does ask the user for user name and/or password on each execution? Or do you want to hardwire both, but it being unique?
0
 
AlexPaceConnect With a Mentor Commented:
Below is a way to do it in a single Robo-FTP script.  In this one, the username and password are only stored in RAM not written to the disk.  This code also detects and reports errors.... so, for example, it won't delete the source file if the download fails.
SET activity = "setting local working folder."
WORKINGDIR "c:\FTP"
IFERROR GOTO fatal_error
PROMPT username "Please enter your username: " "Log in to FTP site"
PROMPT password "Please enter your password: " "Password?" /password
SET activity = "connecting to user folder on FTP site."
FTPLOGON "10.10.100.123" /user=username /pw=password
FTPCD "/sub/folder/"
IFERROR GOTO fatal_error
SET activity = "downloading file."
RCVFILE "text" /as "text.txt" /type=ASCII
IFERROR GOTO fatal_error
FTPDELETE "text"
FTPDELETE "text_temp"
GOTO done
:fatal_error
SET warning = "FTP operation failed while " + activity
MESSAGEBOX warning
:done
FTPLOGOFF
EXIT

Open in new window

0
 
AlexPaceCommented:
Oh, I forgot to mention that when the user types the the password it shows **** instead of the clear text.

Use the -s command line switch to launch Robo-FTP so that it automatically runs a script.  So for example if you saved the above script in the Robo-FTP install folder in a file named prompt.s the command line would look like this:

  C:\Program Files\Robo-FTP 3.7\Robo-FTP.exe" -s"prompt.s"
0
 
ReneGeConnect With a Mentor Commented:
By using SFK:
http://stahlworks.com/dev/index.php?tool=echo

All you have to do, is play with the colors so your happy!!

Cheers,
Rene


@ECHO OFF
color C0
ECHO Please enter password
sfk color red
SET /P PASSWORD=
cls
color C0
echo the password is: %PASSWORD%
PAUSE

Open in new window

0
 
AlexPaceCommented:
That color thing is cool.
0
 
Steve KnightIT ConsultancyCommented:
"color" is built in command btw, you just can't set both foreground / background to the same colour.  SFK looks like it could be useful for a few things mind, especially less sneaky way than my registry for setting same colour -- though suggested that so it didn't need any external tools.

Still not quite sure WHAT is wanted here mind!

Steve
0
 
ReneGeCommented:
Thank Alex !
Steve :)
0
 
LeeTutorretiredCommented:
I've requested that this question be deleted for the following reason:

This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.
0
 
ReneGeCommented:
I actually provided a working solution, and others seems to have put lots of time to help. May I suggest splitting points?
0
 
ReneGeCommented:
I actually provided a working solution, and others seems to have put lots of time to help. May I suggest splitting points?
0
 
ReneGeCommented:
I double post by mistake. Sorry for that!
0
 
Steve KnightIT ConsultancyCommented:
Agreed Rene.

3 way split as three working solutions there we worked on:

Windows native solution: Dragon-it http:#36528030
Windows native solution + tool for setting colour:  ReneGe http:#36546253
Third party tool - RoboFTP:  AlexPace http:#36529993
0
 
South ModModeratorCommented:
All,
 
Following an 'Objection' by ReneGe (at http://www.experts-exchange.com/Q_27390766.html) to the intended closure of this question, it has been reviewed by at least one Moderator and is being closed as recommended by the Expert.
 
At this point I am going to re-start the auto-close procedure.
 
Thank you,
 
SouthMod
Community Support Moderator
0
All Courses

From novice to tech pro — start learning today.