Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Echo off & CD "%~dp0"
- :# REQUIRES buttons.bat [ link below ] to exist in same working directoy
- :# https://pastebin.com/zjwgdZiM
- :# Youtube tutorial for buttons.bat :
- :# https://www.youtube.com/watch?v=ZYhvUbek4Xc
- :# EXAMPLE of a multi user login script for batch RPG's
- :# PURPOSE: Input by clicked letters / numbers only; NO SET /P ; User cannot perform Code Injection.
- Mode 100,40
- If not exist buttons.bat (
- Echo( REQUIRES buttons.bat [ link below ] to exist in same working directoy
- Echo( https://pastebin.com/zjwgdZiM
- Pause
- Goto :Eof
- )
- Call buttons.bat def
- If not Exist "%TEMP%\BG.exe" (
- Echo( REQUIRES BG.exe to be saved in %TEMP%
- Pause
- Goto :Eof
- )
- Goto :main
- ================================:# Functions
- :Confirm [Prompt]
- cls
- Echo(%~1
- %Get.Click% YN
- If not defined ValidClick[YN] Goto :Confirm
- Goto :Eof
- ====
- :End
- %Clean.Exit%
- =====
- :Save - Requires use of # prefixed variable names
- :# Define variables for retention with a # prefix
- :# and output to the !User!_Save.cmd stream by calling this function
- Setlocal EnableDelayedExpansion
- (For /f "Tokens=1,2 Delims==" %%G in ('Set #')Do (
- Set "tmpvar=%%G"
- Set "tmpval=%%H"
- (Echo(Set !tmpvar!=!tmpval!)
- )
- ) >"%~f0:%#User%_Save.cmd"
- Endlocal
- Exit /B 0
- ======
- :Input <Variable> <Prompt> <Descriptor>
- If "%~1" == "" Exit /B 1
- If "%~2" == "" Exit /B 1
- If "%~3" == "" Exit /B 1
- Set "%~1="
- Set "input="
- :BuildInput
- Cls
- Echo(%~2: %\E%[7m!input!%\E%[0m
- %Get.click% Keys
- If not defined Group Goto :BuildInput
- If /I "!Clicked[%Group%]!"=="space" (
- Set "input=!input! "
- Goto:BuildInput
- )
- If /I "!Clicked[%Group%]!"=="backspace" (
- If not "!input!"=="" (Set "input=!input:~0,-1!")Else start /b "" %BG.exe% Play "C:\Windows\Media\Windows Critical Stop.wav"
- Goto:BuildInput
- )
- If /I "!Clicked[%Group%]!"=="done" (
- Goto:finishInput
- )
- For /f "tokens=2 Delims=;" %%G in ("!C{Pos}!")Do For /f "delims=" %%k in ('Set /A "%%G-2"')Do (
- For /f "Tokens=2 Delims=[]" %%i in ("!ValidClick[%Group%]!")Do (
- If not "!btn[keys][%%i][string]:~%%k,1!"==" " Set "input=!input!!btn[keys][%%i][string]:~%%k,1!"
- )
- )
- Goto:BuildInput
- :finishInput
- Set "%~1=!Input!"
- If Not Defined %~1 (
- start /b "" %BG.exe% Play "C:\Windows\Media\Windows Critical Stop.wav"
- Echo(%~3 required
- Endlocal
- Pause
- Goto :Input
- )
- Exit /B 0
- :Main
- Cls
- Setlocal EnableDelayedExpansion
- %Make.btn% postLogin /S Delete user /y 3 /x 3 /bo 33 /N
- %Make.btn% postLogin /S Change Password /y 3 /bo 34
- %Make.btn% postLogin /S Exit /y 3 /bo 31
- %Make.btn% postLogin /S Continue /y 3 /bo 32
- %Make.btn% Keys /S " 1234567890 " /Y 5 /bo 34 /N
- %Make.btn% Keys /S " QWERTYUIOP qwertyuiop " /bo 34
- %Make.btn% Keys /S " ASDFGHJKL asdfghjkl " /bo 34
- %Make.btn% Keys /S " ZXCVBNM zxcvbnm " /bo 34
- %Make.btn% Keys /S Space /Y 17 /X 2 /bo 34
- %Make.btn% Keys /S Done /Y 17 /X 10 /bo 32
- %Make.btn% Keys /S Backspace /X 18 /Y 17 /bo 34
- %Make.btn% Quit /S "Exit" /bo 31 /N /Y 38
- %Make.btn% YN /S Yes /y 4 /bo 32 /N
- %Make.btn% YN /S No /y 4 /bo 31
- Set "Users=0"
- For /f "Skip=6 Tokens=2 Delims=:" %%G in ('Dir /R "%~f0"^|Findstr /vc:"_Save.cmd"')Do Set /A Users+=1
- If not !Users! GEQ 10 %Make.Btn% Users /S New User /N
- For /f "Skip=6 Tokens=2 Delims=:" %%G in ('Dir /R "%~f0"^|Findstr /vc:"_Save.cmd"')Do %Make.Btn% Users /S %%G
- :Login
- For /f "tokens=1 Delims==" %%G in ('Set # 2^> nul')Do Set "%%G=" 2> nul
- Set "#Status=New"
- Cls
- :username
- cls
- %Get.Click% Users
- If not defined Group Goto:username
- If "!Clicked[Users]!"=="New User" (
- Call :input #User "Enter your username" "Username"
- )Else Set "#User=!btn%ValidClick[Users]%[String]!"
- Title [!#User!]
- :Verify
- Cls
- More < "%~f0:!#User!" > nul 2>&1 && (
- Set "#Pass="
- Call :input #Pass "Enter your current password" "Password"
- (More < "%~f0:!#User!"|findstr.exe /LXC:"!#Pass!") > nul 2>&1 || (
- Call :Confirm "Password invalid. Try again?"
- If "!Clicked[YN]!"=="Yes" Goto:Login
- Goto :End
- )
- )
- If "!#Pass!"=="" (
- cls
- Call :input #Pass "Enter your new password" Password
- Call :input PassC "Confirm your password" Password
- If not "!#Pass!" == "!PassC!" (
- Echo(Passwords do not match.
- Pause
- Goto :Login
- )
- (Echo(!#Pass!) >"%~f0:!#User!" 2>Nul || (
- Echo(Password contains invalid characters.
- Goto :Verify
- )
- Call :Save
- )
- :ReturnAction
- cls
- %Get.Click% PostLogin
- If not defined Group Goto:ReturnAction
- If /I "!Clicked[%Group%]!"=="Delete User" (
- Call :Confirm "Are you Sure?"
- If "!Clicked[YN]!"=="No" Goto:ReturnAction
- (Powershell -c "remove-item -path '%~nx0' -Stream '!#User!_Save.cmd'") 2> nul
- (Powershell -c "remove-item -path '%~nx0' -Stream '!#User!'") 2> nul
- Endlocal
- Goto :main
- )
- If /I "!Clicked[%Group%]!"=="Change Password" (
- more < "%~f0:%#User%_Save.cmd" > nul 2> null && For /F "UsebackQ Delims=" %%G in ("%~f0:%#User%_Save.cmd")Do %%G
- Call :input #Pass "Enter your new password" Password
- Call :input PassC "Confirm your new password" Password
- If not "!#Pass!" == "!PassC!" (
- Echo(Passwords do not match.
- Pause
- Goto :ReturnAction
- )
- (Echo(!#Pass!) >"%~f0:!#User!" 2>Nul || (
- Echo(Username contains invalid characters.
- Timeout /t 3 /Nobreak
- Goto :Verify
- )
- Call :Save
- )
- If /I "!Clicked[%Group%]!"=="Exit" %Clean.Exit%
- :Start
- :# Load user information from the users stream.
- more < "%~f0:%#User%_Save.cmd" > nul 2> nul && For /F "UsebackQ Delims=" %%G in ("%~f0:%#User%_Save.cmd")Do %%G
- rem demo restoration of saved values. Substitute with your script below
- Set #
- Set #Status=returned
- Call :Save
- :Quit
- %Get.Click% Quit
- If not Defined Group Goto :Quit
- Goto :end
Add Comment
Please, Sign In to add comment