Created
April 24, 2014 19:17
-
-
Save rubenwardy/11266183 to your computer and use it in GitHub Desktop.
Batch login system, for fun
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
REM To set up, create a text file called users.txt | |
REM in the same directory as this batch file | |
REM with this content (without the REM) | |
REM 1,user1,password,staff | |
REM 2,user2,password,pupil | |
@ECHO OFF | |
SETLOCAL EnableDelayedExpansion | |
GOTO main | |
:extract_user | |
ECHO Finding %2 in %1 | |
ECHO Output: %3 | |
DEL %3 | |
FOR /f %%G IN (%1) DO ( | |
SET "var=%%G" | |
SET "uid=!var:~0,1!" | |
ECHO !uid! | |
if "!uid!"=="%2" ( | |
ECHO %%G>>"%3" | |
) | |
) | |
GOTO :EOF | |
:user_parse | |
SET data= | |
FOR /f %%G IN (%1) DO ( | |
SET "data=!data!%%G" | |
) | |
SET user_name= | |
SET user_pass= | |
SET stage=1 | |
SET "data=!data:~1%!" | |
SET "data=!data:~1%!" | |
:username_loop | |
SET "char=!data:~0,1!" | |
SET "data=!data:~1%!" | |
IF "%char%"=="," ( | |
GOTO password_loop | |
) ELSE ( | |
SET "user_name=!user_name!%char%" | |
) | |
GOTO username_loop | |
:password_loop | |
SET "char=!data:~0,1!" | |
SET "data=!data:~1%!" | |
IF "%char%"=="," ( | |
GOTO rank_loop | |
) ELSE ( | |
SET "user_pass=!user_pass!%char%" | |
) | |
GOTO password_loop | |
:rank_loop | |
GOTO :EOF | |
:main | |
SET /p inp_user="Enter your username: " %=% | |
SET /p inp_pass="Enter your password: " %=% | |
FOR /f %%G IN (users.txt) DO ( | |
DEL tmp.txt | |
ECHO %%G>>"tmp.txt" | |
CALL :user_parse tmp.txt | |
IF "!user_name!" == "%inp_user%" ( | |
if "!user_pass!" == "%inp_pass%" ( | |
ECHO Logging in... | |
GOTO loggedin | |
) else ( | |
GOTO accd | |
) | |
) | |
) | |
:accd | |
ECHO Access denied | |
GOTO end | |
:loggedin | |
ECHO You are logged in! | |
PAUSE | |
:end | |
ECHO Program Ended | |
PAUSE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment