Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- File path for storing the PIN
- local pinFilePath = "/disk/security/PIN.config"
- -- Function to read the PIN from file or use default if not available
- local function readPINFromFile()
- local file = fs.open(pinFilePath, "r")
- local pin = file and file.readLine() or "1234"
- if file then
- file.close()
- end
- return pin
- end
- -- Define your PIN
- local correctPIN = readPINFromFile()
- -- GUI Functions
- local function drawScreen()
- term.clear()
- term.setCursorPos(1, 1)
- print("+-----+-----+-----+")
- print("| | | |")
- print("| 1 | 2 | 3 |")
- print("| | | |")
- print("+-----+-----+-----+")
- print("| | | |")
- print("| 4 | 5 | 6 |")
- print("| | | |")
- print("+-----+-----+-----+")
- print("| | | |")
- print("| 7 | 8 | 9 |")
- print("| | | |")
- print("+-----+-----+-----+")
- print("| | | |")
- print("| C | 0 | E |")
- print("| | | |")
- print("+-----+-----+-----+")
- term.setCursorPos(1, 18)
- write("Enter PIN:")
- end
- local function handleMouseClick(x, y)
- if x >= 2 and x <= 5 and y >= 2 and y <= 4 then
- return 1
- elseif x >= 8 and x <= 11 and y >= 2 and y <= 4 then
- return 2
- elseif x >= 14 and x <= 17 and y >= 2 and y <= 4 then
- return 3
- elseif x >= 2 and x <= 5 and y >= 6 and y <= 8 then
- return 4
- elseif x >= 8 and x <= 11 and y >= 6 and y <= 8 then
- return 5
- elseif x >= 14 and x <= 17 and y >= 6 and y <= 8 then
- return 6
- elseif x >= 2 and x <= 5 and y >= 10 and y <= 12 then
- return 7
- elseif x >= 8 and x <= 11 and y >= 10 and y <= 12 then
- return 8
- elseif x >= 14 and x <= 17 and y >= 10 and y <= 12 then
- return 9
- elseif x >= 2 and x <= 5 and y >= 14 and y <= 16 then
- return "C" -- Clear
- elseif x >= 8 and x <= 11 and y >= 14 and y <= 16 then
- return 0
- elseif x >= 14 and x <= 17 and y >= 14 and y <= 16 then
- return "E" -- Enter
- else
- return nil
- end
- end
- -- Main PIN Entry Function
- local function enterPIN()
- local enteredPIN = ""
- local attempts = 3
- while attempts > 0 do
- drawScreen()
- term.setCursorBlink(false)
- term.setCursorPos(12, 18)
- write(string.rep("*", #enteredPIN))
- local event, _, x, y = os.pullEvent("mouse_click")
- if event == "mouse_click" then
- local button = handleMouseClick(x, y)
- if button then
- if button == "C" then
- -- Clear button
- enteredPIN = ""
- elseif button == "E" then
- -- Enter button
- if enteredPIN == correctPIN then
- term.clear()
- term.setCursorPos(1, 1)
- print("Access Granted!")
- -- Perform actions upon successful entry
- break
- else
- term.clear()
- term.setCursorPos(1, 1)
- print("Incorrect PIN. Try again.")
- attempts = attempts - 1
- if attempts == 0 then
- print("Access Denied!")
- else
- print("Attempts remaining: " .. attempts)
- end
- sleep(2)
- enteredPIN = ""
- end
- else
- enteredPIN = enteredPIN .. tostring(button)
- end
- end
- end
- end
- end
- -- Start PIN Entry
- enterPIN()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement