Advertisement
DOGGYWOOF

android lock screen

Jan 8th, 2024 (edited)
14
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. -- Define your PIN
  2. local correctPIN = "1234"
  3.  
  4. -- GUI Functions
  5. local function drawScreen()
  6. term.clear()
  7. term.setCursorPos(1, 1)
  8. print("+-----+-----+-----+")
  9. print("| | | |")
  10. print("| 1 | 2 | 3 |")
  11. print("| | | |")
  12. print("+-----+-----+-----+")
  13. print("| | | |")
  14. print("| 4 | 5 | 6 |")
  15. print("| | | |")
  16. print("+-----+-----+-----+")
  17. print("| | | |")
  18. print("| 7 | 8 | 9 |")
  19. print("| | | |")
  20. print("+-----+-----+-----+")
  21. print("| | | |")
  22. print("| C | 0 | E |")
  23. print("| | | |")
  24. print("+-----+-----+-----+")
  25. term.setCursorPos(1, 18)
  26. write("Enter PIN:")
  27. end
  28.  
  29. local function handleMouseClick(x, y)
  30. if x >= 2 and x <= 5 and y >= 2 and y <= 4 then
  31. return 1
  32. elseif x >= 8 and x <= 11 and y >= 2 and y <= 4 then
  33. return 2
  34. elseif x >= 14 and x <= 17 and y >= 2 and y <= 4 then
  35. return 3
  36. elseif x >= 2 and x <= 5 and y >= 6 and y <= 8 then
  37. return 4
  38. elseif x >= 8 and x <= 11 and y >= 6 and y <= 8 then
  39. return 5
  40. elseif x >= 14 and x <= 17 and y >= 6 and y <= 8 then
  41. return 6
  42. elseif x >= 2 and x <= 5 and y >= 10 and y <= 12 then
  43. return 7
  44. elseif x >= 8 and x <= 11 and y >= 10 and y <= 12 then
  45. return 8
  46. elseif x >= 14 and x <= 17 and y >= 10 and y <= 12 then
  47. return 9
  48. elseif x >= 2 and x <= 5 and y >= 14 and y <= 16 then
  49. return "C" -- Clear
  50. elseif x >= 8 and x <= 11 and y >= 14 and y <= 16 then
  51. return 0
  52. elseif x >= 14 and x <= 17 and y >= 14 and y <= 16 then
  53. return "E" -- Enter
  54. else
  55. return nil
  56. end
  57. end
  58.  
  59. -- Main PIN Entry Function
  60. local function enterPIN()
  61. local enteredPIN = ""
  62. local attempts = 3
  63.  
  64. while attempts > 0 do
  65. drawScreen()
  66. term.setCursorBlink(false)
  67. term.setCursorPos(12, 18)
  68. write(string.rep("*", #enteredPIN))
  69. local event, _, x, y = os.pullEvent("mouse_click")
  70.  
  71. if event == "mouse_click" then
  72. local button = handleMouseClick(x, y)
  73. if button then
  74. if button == "C" then
  75. -- Clear button
  76. enteredPIN = ""
  77. elseif button == "E" then
  78. -- Enter button
  79. if enteredPIN == correctPIN then
  80. term.clear()
  81. term.setCursorPos(1, 1)
  82. print("Access Granted!")
  83. -- Perform actions upon successful entry
  84. break
  85. else
  86. term.clear()
  87. term.setCursorPos(1, 1)
  88. print("Incorrect PIN. Try again.")
  89. attempts = attempts - 1
  90. if attempts == 0 then
  91. print("Access Denied!")
  92. else
  93. print("Attempts remaining: " .. attempts)
  94. end
  95. sleep(2)
  96. enteredPIN = ""
  97. end
  98. else
  99. enteredPIN = enteredPIN .. tostring(button)
  100. end
  101. end
  102. end
  103. end
  104. end
  105.  
  106. -- Start PIN Entry
  107. enterPIN()
  108.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement