-2

I have this batch program. I want a verification system where you type the code, and it lets you continue. If you type the wrong code it won't let you continue.

Anyone got some code I can use for this?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
  • http://stackoverflow.com/questions/5487473/how-to-create-an-infinite-loop-in-windows-batch-file – Isaac Sep 29 '16 at 04:46
  • Can you give me the exact code please? – Foetheorize Sep 29 '16 at 04:50
  • 4
    See `set /p`, `goto /?`, and `if /?`. –  Sep 29 '16 at 04:51
  • @Foetheorize no I can't? – Isaac Sep 29 '16 at 04:52
  • 4
    They should really make people read all the howto articles on SO and give them a test before they are allowed to post questions. – Squashman Sep 29 '16 at 05:08
  • I totally agree, @Squashman. New users should at least have the [Informed](http://stackoverflow.com/help/badges/2600/informed) badge, so they have at least opended the [tour page](http://stackoverflow.com/tour) and scrolled to the bottom (this does still not prove whether they read *and* understood it though...). – aschipfl Sep 29 '16 at 12:13

1 Answers1

0

say if you wanted the password to be "1234" you would put:

@echo off
echo Enter the correct code:
set /p InputPass=Code: 
if '%InputPass%'=='1234' goto :AccessGranted
goto :AccessDenied

:AccessGranted
cls
echo Access Granted!
timeout 3 /nobreak >nul
goto :continue

:AccessDenied
cls
echo Access Denied!
echo Program on halt!
pause >nul
goto :AccessDenied

:continue

And then you would put in the code you want to execute if the user got it right, under the last line (which says :continue)

J03L
  • 314
  • 3
  • 17