Advertisement
DOGGYWOOF

PIN confirm

Mar 12th, 2024 (edited)
7
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. -- PIN Configuration Script with Confirmation and Masked Input
  2.  
  3. local configFile = "/disk/security/PIN.config"
  4.  
  5. -- Function to display a simple GUI
  6. local function displayGUI()
  7. term.clear()
  8. term.setCursorPos(1, 1)
  9. print("Set PIN for Lockscreen:")
  10. end
  11.  
  12. -- Function to get masked input
  13. local function maskedInput()
  14. local input = ""
  15. term.setCursorBlink(true)
  16. while true do
  17. local _, key = os.pullEvent("key")
  18. if key == keys.enter then
  19. print()
  20. term.setCursorBlink(false)
  21. break
  22. elseif key == keys.backspace then
  23. if #input > 0 then
  24. input = input:sub(1, #input - 1)
  25. term.setCursorPos(term.getCursorPos() - 1, term.getCursorY())
  26. write(" ") -- Replace the last character with a space
  27. term.setCursorPos(term.getCursorPos() - 1, term.getCursorY())
  28. end
  29. elseif key >= 32 and key <= 126 then
  30. input = input .. string.char(key)
  31. write("*")
  32. end
  33. end
  34. return input
  35. end
  36.  
  37. -- Function to get input and save PIN to file
  38. local function setPIN()
  39. local pin
  40. local confirmedPin
  41.  
  42. -- Get the first PIN entry
  43. term.setCursorPos(1, 3)
  44. write("Enter PIN: ")
  45. pin = maskedInput()
  46.  
  47. -- Get the second PIN entry for confirmation
  48. term.setCursorPos(1, 4)
  49. write("Confirm PIN: ")
  50. confirmedPin = maskedInput()
  51.  
  52. -- Check if the two PINs match
  53. if pin == confirmedPin then
  54. -- Open the file in write mode and save the PIN
  55. local file = fs.open(configFile, "w")
  56. file.write(pin)
  57. file.close()
  58.  
  59. print("PIN set successfully!")
  60. else
  61. print("PIN entries do not match. Please try again.")
  62. setPIN()
  63. end
  64. end
  65.  
  66. -- Main function
  67. local function main()
  68. displayGUI()
  69. setPIN()
  70. end
  71.  
  72. -- Run the main function
  73. main()
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement