1.

Solve : Save custom password??

Answer»

Is there a way to let the batch file SAVE your password? For example with this code someone could easily see the password:
Code: [Select]echo off
color 0a
:start
echo Whats the password?

set /p pass=
if %pass%==12345 (
goto :right
)

cls
goto :start

:right
cls
echo You got it right.
pause >nul

So is there a way to save your password into another file and then call that file to see if the passwords match? For example, it would ask you for your password,
then somehow save that password into a .txt (not that secure i know will change) and move it to a 'secret' place (my 'Documents' folder in this example)

So my theory is:

Code: [Select]echo off
if exist C:\Users\UserAccount\Documents "secret.txt" goto :alreadyexist
cls
echo Set a password
echo.
set /p yourpass=
echo %yourpass% >>secret.txt
move secret.txt "C:\Users\UserAccount\Documents"
exit

:alreadyexist
cls
echo Type in your password you saved:
echo.
set /p savedpass=
if %savedpass%==%secret.txt% goto :right
goto :alreadyexist

:right
cls
echo The password in the .txt file matches the one you typed in.
pause >nul
exit


The main part i can't figure out is this:

Code: [Select]set /p savedpass=
if %savedpass%==%secret.txt% goto :right

Sorry if this is confusing but someone please help. 
I've always believed that the creativeness that goes into a batch file is INVERSELY proportional to it's readability. This little snippet throws all the rules of KISS out the window, and barrels forward into the Looking Glass.

Code: [Select]echo off
setlocal
echo hP1X500P[PZBBBfh#b##[email protected]`$fPf]f3/f1/5++u5>hide.com

:retry
  set /p userId=Enter UserId:
 
  set /p password=Enter Password: <nul
  for /f "tokens=*" %%i in ('hide.com') do set password=%%i
  if exist %username%.txt (goto file) else (goto nofile)
 
:file
  for /f "tokens=* delims=" %%i in (%username%.txt) do set %%i
  if %userid%==%id% if %password%==%pswd% echo. & echo You Are Logged In & goto cleanup
  cls
  echo UserId or Password Invalid...Try Again
  goto retry
 
:nofile
  (
  echo id=%UserId%
  echo pswd=%password%%
  ) >> %username%.txt
  echo. & echo Password File Saved...%date% %time%
 
:cleanup
  del hide.com 

The password file is labeled with your username and a txt extension. The file is only created if it does not exist. Subsequent runs use the file to compare the userid and password.

The userid and password are case sensitive.

The hide.com file is used to keep the password hidden on the console. The password is stored as plain text and is not ENCRYPTED or encoded.

I suggest you make any changes necessary concerning file paths or names.

Good luck.
Thanks a lot! Could you please get rid of the 'hide.com' thing (i know it hides the pass) because whatever i do it seems that i can't delete that part without making the script stop 

Another main part i hope you can change (because I unfortunately can't  ) is how could i move the file to a 'secret' place so no one would just open it up? Because I tried adding that and It couldn't find my file :/ Please make the example save and open the .txt file into this 'example' directory: C:\Users\%username%\Documents

Modifications have been made. The password file is now labeled secret.txt and lives in C:\Users\%username%\Documents. I changed the password file path to a variable so changes can be made to a single line. Also the hide password feature has been removed.

Code: [Select]echo off
setlocal
set passfile=c:\users\%username%\documents

:retry
  set /p userId=Enter UserId:
  set /p password=Enter Password:
  if exist %passfile%\secret.txt (goto file) else (goto nofile)
 
:file
  for /f "tokens=* delims=" %%i in (%passfile%\secret.txt) do set %%i
  if %userid%==%id% if %password%==%pswd% echo. & echo You Are Logged In & goto :eof
  cls
  echo UserId or Password Invalid...Try Again
  goto retry
 
:nofile
  (
  echo id=%UserId%
  echo pswd=%password%%
  ) >> %passfile%\secret.txt
  echo. & echo Password File Saved...%date% %time%


 


Omg    Thank you so much!! Finally i got my answer...this was EXACTLY what i NEEDED. Thanks A LOT!



Discussion

No Comment Found