Solved

Batch File with Hide Password

Posted on 2011-09-12
19
1,656 Views
Last Modified: 2012-05-12
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

0
Comment
Question by:palddl
  • 5
  • 3
  • 3
  • +6
19 Comments
 
LVL 13

Expert Comment

by:stergium
ID: 36527570
hello.
i've never heard or seen a non plaintext batch file. i dont think that its possible
0
 
LVL 1

Author Comment

by:palddl
ID: 36527578
ok give also plaintext method
0
 
LVL 17

Expert Comment

by:Shanmuga Sundaram
ID: 36527606
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
 
LVL 68

Expert Comment

by:Qlemo
ID: 36527690
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
 
LVL 43

Accepted Solution

by:
Steve Knight earned 167 total points
ID: 36528030
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
 
LVL 16

Assisted Solution

by:AlexPace
AlexPace earned 166 total points
ID: 36529993
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
 
LVL 16

Expert Comment

by:AlexPace
ID: 36530058
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
 
LVL 10

Assisted Solution

by:ReneGe
ReneGe earned 167 total points
ID: 36546253
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 16

Expert Comment

by:AlexPace
ID: 36548315
That color thing is cool.
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36548378
"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
 
LVL 10

Expert Comment

by:ReneGe
ID: 36548546
Thank Alex !
Steve :)
0
 
LVL 59

Expert Comment

by:LeeTutor
ID: 36949311
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
 
LVL 10

Expert Comment

by:ReneGe
ID: 36949303
I actually provided a working solution, and others seems to have put lots of time to help. May I suggest splitting points?
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36949312
I actually provided a working solution, and others seems to have put lots of time to help. May I suggest splitting points?
0
 
LVL 10

Expert Comment

by:ReneGe
ID: 36949319
I double post by mistake. Sorry for that!
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 36949542
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
 

Expert Comment

by:South Mod
ID: 36998364
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

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

The use of stolen credentials is a hot commodity this year allowing threat actors to move laterally within the network in order to avoid breach detection.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…
The Task Scheduler is a powerful tool that is built into Windows. It allows you to schedule tasks (actions) on a recurring basis, such as hourly, daily, weekly, monthly, at log on, at startup, on idle, etc. This video Micro Tutorial is a brief intro…

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now