Reputation: 61
i have tried this, but it keeps returning an error saying the syntax of the command is incorrect
. Here is the code i tried:
@echo off
echo Enter Username and Password to view files
set /p user=Enter UserId:
set /p pass=Enter Password:
if /i %user%==admin (if /i %pass%==*my password was here*)
(goto admin1)
:admin1
..etc..
Upvotes: 1
Views: 13843
Reputation: 3375
Your parenthesis are off.
@echo off
echo Enter Username and Password to view files
set /p user=Enter UserId:
set /p pass=Enter Password:
if /i "%user%"=="admin" (if /i "%pass%"=="password" goto admin1)
goto skip
:admin1
echo Done
goto END
:skip
:END
Upvotes: 0
Reputation: 3900
The problem with your code is your use of parenthesis. Here's a re-done version of the same code.
@echo off
echo Enter Username and Password to view files
set /p user=Enter UserID:
set /p pass=Enter Password:
if /i %user%==admin (
if /i %pass%==password goto admin1
)
:admin1
::More here...
Also, there is one thing wrong with this code (and yours, if it worked). No matter what user or password you put in, it would always go to :admin1
. This is because batch files read from top to bottom, so it would skip the code within the if
block and go to the :admin1
block.
You can combat this by putting code in between the code that will redirect the user.
Also, I suggest you look at the formatting help to format your question correctly (putting code in code blocks, links, etc).
Upvotes: 1