Advertisement
DOGGYWOOF

Andoid screen lock

Jan 8th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.10 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. -- Main PIN Entry Function
  30. local function enterPIN()
  31. local enteredPIN = ""
  32. local attempts = 3
  33.  
  34. while attempts > 0 do
  35. drawScreen()
  36. term.setCursorBlink(false)
  37. term.setCursorPos(12, 18)
  38. write(string.rep("*", #enteredPIN))
  39. local _, key = os.pullEvent("key")
  40. local number = tonumber(string.char(key))
  41.  
  42. if number and number >= 0 and number <= 9 then
  43. enteredPIN = enteredPIN .. tostring(number)
  44. elseif key == keys.backspace then
  45. enteredPIN = string.sub(enteredPIN, 1, -2)
  46. elseif key == keys.enter then
  47. if enteredPIN == correctPIN then
  48. term.clear()
  49. term.setCursorPos(1, 1)
  50. print("Access Granted!")
  51. -- Perform actions upon successful entry
  52. break
  53. else
  54. term.clear()
  55. term.setCursorPos(1, 1)
  56. print("Incorrect PIN. Try again.")
  57. attempts = attempts - 1
  58. if attempts == 0 then
  59. print("Access Denied!")
  60. else
  61. print("Attempts remaining: " .. attempts)
  62. end
  63. sleep(2)
  64. enteredPIN = ""
  65. end
  66. end
  67. end
  68. end
  69.  
  70. -- Start PIN Entry
  71. enterPIN()
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement