I'm trying to create a batch file that checks if
- the directory
C:\Pswrd.Zask
, - the user name file
C:\Pswrd.Zask\Username.Zask
, - and the password file
C:\Pswrd.Zask\Password.Zask
all exist.
The batch processing should continue on PasswordScreen
if the two files in the directory exist.
But batch processing should continue on CreatePasswordScreen
if they don't exist all.
The create CreatePasswordScreen
block asks for user input. That input is then stored into a file named Password.Zask
& Username.Zask
inside the folder C:\Pswrd.Zask
.
On second run of the program, the program checks existence of that folder, the user name file and the password file, and then sets the user name & password from the two files in C:\Pswrd.Zask
to variables right before the PasswordScreen
block which will be used to determine if the password is correct or not.
The problem is that I cannot get the password and user name to store correctly in the batch file as a variable without the batch process ultimately coming to a end for an unknown reason.
Did I miss use a command?
The problem should be right under then line that says :UsernameExist
.
@echo off
color 0a
if not exist "C:\Pswrd.Zask\" (
mkdir "C:\Pswrd.Zask\"
if "!errorlevel!" EQU "0" (
goto DirectoryExist
) else (
echo Created the folder "C:\Pswrd.Zask"
)
) else (
goto DirectoryExist
)
:DirectoryExist
if exist C:\Pswrd.Zask\Password.Zask (
goto PasswordExist
) else (
goto CreatePasswordScreen
)
:PasswordExist
if exist C:\Pswrd.Zask\Username.Zask (
goto UsernameExist
) else (
goto CreatePasswordScreen
)
:UsernameExist
for /f "Delims=" %%A in (C:\Pswrd.Zask\Password.Zask) do (
set CHECKPASSWORD=%%A
for /f "Delims=" %%B in (C:\Pswrd.Zask\Username.Zask) do (
set CHECKUSERNAME=%%B
goto PasswordScreen
:CreatePasswordScreen
cls
echo Create a password.
echo.
set /p "CREATEPASSWORD= Enter password : "
set /p "CREATEUSERNAME= Enter username : "
echo %CREATEPASSWORD% >> C:\Pswrd.Zask\Password.Zask
attrib C:\Pswrd.Zask\Password.Zask -s -h & echo Password Created!
echo %CREATEUSERNAME% >> C:\Pswrd.Zask\Username.Zask
attrib C:\Pswrd.Zask\Username.Zask -s -h & echo Username Created!
echo.
echo Loading...
timeout /5
:PasswordScreen
color 0a
cls
echo Existing User Account.
echo.
set /p "PASSWORD= Enter Password : "
set /p "USERNAME= Enter Username : "
if %PASSWORD%==%CHECKPASSWORD% goto Operation1True
if not %PASSWORD%==%CHECKPASSWORD% goto OperationFalse
:Operation1True
if %PASSWORD%==%CHECKPASSWORD% goto Operation2True
if not %PASSWORD%==%CHECKPASSWORD% goto OperationFalse
:OperationFalse
color 0c
echo Password Incorrect!
timeout /10
goto PasswordScreen
:Operation2True
cls
echo Password Correct!
pause
I figured out the solution, i chanced it to the following.
@echo off
color 0a
if not exist "C:\Pswrd.Zask\" (
mkdir "C:\Pswrd.Zask\"
if "!errorlevel!" EQU "0" (
goto DirectoryExist
) else (
echo Created the folder "C:\Pswrd.Zask" & timeout /t 5
)
) else (
goto DirectoryExist
)
:DirectoryExist
if exist C:\Pswrd.Zask\Password.Zask (
goto PasswordExist
) else (
goto CreatePasswordScreen
)
:PasswordExist
if exist C:\Pswrd.Zask\Username.Zask (
goto UsernameExist
) else (
goto CreatePasswordScreen
)
:UsernameExist
for /f "Delims=" %%A in (C:\Pswrd.Zask\Password.Zask) do (
set CHECKPASSWORD=%%A
)
for /f "Delims=" %%B in (C:\Pswrd.Zask\Username.Zask) do (
set CHECKUSERNAME=%%B
)
goto PasswordScreen
:CreatePasswordScreen
cls
echo Create a password.
echo.
set /p "CREATEPASSWORD= Enter password : "
set /p "CREATEUSERNAME= Enter username : "
echo %CREATEPASSWORD% >> C:\Pswrd.Zask\Password.Zask
attrib C:\Pswrd.Zask\Password.Zask +s +h & echo Password Created!
echo %CREATEUSERNAME% >> C:\Pswrd.Zask\Username.Zask
attrib C:\Pswrd.Zask\Username.Zask +s +h & echo Username Created!
start %~n0%~x0
exit
:PasswordScreen
color 0a
cls
echo Existing User Account.
echo.
set /p "PASSWORD= Enter Password : "
set /p "USERNAME= Enter Username : "
if %PASSWORD%==%CHECKPASSWORD% (
goto Operation1True
) else (
goto OperationFalse
)
:Operation1True
if %USERNAME%==%CHECKUSERNAME% (
goto Operation2True
) else (
goto OperationFalse
)
:OperationFalse
color 0c
echo Password Incorrect!
timeout /t 10
goto PasswordScreen
:Operation2True
cls
echo Password Correct!
echo.
pause