How to make multiple variable acceptable while whitelisting any other variable?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
ZolarKeth
Posts: 1
Joined: 12 Sep 2017 19:46

How to make multiple variable acceptable while whitelisting any other variable?

#1 Post by ZolarKeth » 12 Sep 2017 19:57

I'm not very good at batch, and I'm trying to create this fake "hacker" so my friends and I can roleplay "nerdy I know lolz :lol: "
Anyways, here's the code if you need it.


@echo off

echo . . .
PING 1.1.1.1 -n 1 -w 2000 >NUL
goto Startup

:Startup
cls
echo Verifying User... input registered account credentials.
set /p Credentials=

if %Credentials%==VK11Cyanide06 goto Correct
if %Credentials%==QX19Trojan87 goto Cracked
if %Credentials% NOT==VK11Cyanide06 OR QX19Trojan87 goto Incorrect

I want VK11Cyanide06 and QX19Trojan87 to be acceptable variables and all other variables to goto "Incorrect". Can anyone tell me how to accomplish this?

ShadowThief
Expert
Posts: 1163
Joined: 06 Sep 2013 21:28
Location: Virginia, United States

Re: How to make multiple variable acceptable while whitelisting any other variable?

#2 Post by ShadowThief » 13 Sep 2017 03:07

Just remove the

Code: Select all

if %Credentials% NOT==VK11Cyanide06 OR QX19Trojan87
part of the last line. Batch scripts are read top-down, so once the first two if statements are passed and ignored, everything else will automatically go to Incorrect.

elzooilogico
Posts: 128
Joined: 23 May 2016 15:39
Location: Spain

Re: How to make multiple variable acceptable while whitelisting any other variable?

#3 Post by elzooilogico » 13 Sep 2017 04:10

Whenever you must evaluate two variables to boolean logic between them

Code: Select all

@echo off
setlocal

set /p var1="Val1, enter true or false: "
set /p var2="Val2, enter true or false: "

rem test AND
if "%var1%"=="true" if "%var2%"=="true" (
  echo/&echo/Both are true & goto :done
)

rem test NOT logic
if not "%var1%"=="true" if not "%var2%"=="true" (
  echo/&echo/None are true & goto :done
)

rem else OR
echo/&echo/One is true
:done
endlocal
exit/B

Post Reply