Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- PIN Configuration Script with Confirmation and Masked Input
- local configFile = "/disk/security/PIN.config"
- -- Function to display a simple GUI
- local function displayGUI()
- term.clear()
- term.setCursorPos(1, 1)
- print("Set PIN for Lockscreen:")
- end
- -- Function to get masked input
- local function maskedInput()
- local input = ""
- term.setCursorBlink(true)
- while true do
- local _, key = os.pullEvent("key")
- if key == keys.enter then
- print()
- term.setCursorBlink(false)
- break
- elseif key == keys.backspace then
- if #input > 0 then
- input = input:sub(1, #input - 1)
- term.setCursorPos(term.getCursorPos() - 1, term.getCursorY())
- write(" ") -- Replace the last character with a space
- term.setCursorPos(term.getCursorPos() - 1, term.getCursorY())
- end
- elseif key >= 32 and key <= 126 then
- input = input .. string.char(key)
- write("*")
- end
- end
- return input
- end
- -- Function to get input and save PIN to file
- local function setPIN()
- local pin
- local confirmedPin
- -- Get the first PIN entry
- term.setCursorPos(1, 3)
- write("Enter PIN: ")
- pin = maskedInput()
- -- Get the second PIN entry for confirmation
- term.setCursorPos(1, 4)
- write("Confirm PIN: ")
- confirmedPin = maskedInput()
- -- Check if the two PINs match
- if pin == confirmedPin then
- -- Open the file in write mode and save the PIN
- local file = fs.open(configFile, "w")
- file.write(pin)
- file.close()
- print("PIN set successfully!")
- else
- print("PIN entries do not match. Please try again.")
- setPIN()
- end
- end
- -- Main function
- local function main()
- displayGUI()
- setPIN()
- end
- -- Run the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement