Advertisement
DOGGYWOOF

Recovery Key authenticaton

Dec 9th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. -- Function to draw a border
  2. local function drawBorder()
  3. term.clear()
  4. local w, h = term.getSize()
  5. for y = 1, h do
  6. term.setCursorPos(1, y)
  7. term.write("|")
  8. term.setCursorPos(w, y)
  9. term.write("|")
  10. end
  11. for x = 1, w do
  12. term.setCursorPos(x, 1)
  13. term.write("-")
  14. term.setCursorPos(x, h)
  15. term.write("-")
  16. end
  17. term.setCursorPos(1, 1)
  18. term.write("+")
  19. term.setCursorPos(w, 1)
  20. term.write("+")
  21. term.setCursorPos(1, h)
  22. term.write("+")
  23. term.setCursorPos(w, h)
  24. term.write("+")
  25. end
  26.  
  27. -- Function to center text on the screen
  28. local function centerText(text, y)
  29. local w, _ = term.getSize()
  30. local x = math.floor((w - #text) / 2) + 1
  31. term.setCursorPos(x, y)
  32. term.write(text)
  33. end
  34.  
  35. -- Function to verify the recovery key
  36. local function verifyRecoveryKey()
  37. local keyPath = "/disk/security/RecoveryKey.txt"
  38. if fs.exists(keyPath) then
  39. local file = fs.open(keyPath, "r")
  40. local storedKey = file.readAll()
  41. file.close()
  42.  
  43. term.clear()
  44. drawBorder()
  45. centerText("Enter Recovery Key", 3)
  46. term.setCursorPos(5, 5)
  47. term.write("Recovery Key: ")
  48. local enteredKey = read()
  49.  
  50. if enteredKey == storedKey then
  51. centerText("Recovery successful. Welcome!", 8)
  52. os.sleep(2)
  53. return true
  54. else
  55. centerText("Invalid Recovery Key. Access denied.", 8)
  56. os.sleep(2)
  57. end
  58. else
  59. centerText("Recovery Key not found. Access denied.", 8)
  60. os.sleep(2)
  61. end
  62. return false
  63. end
  64.  
  65. -- Function to start recovery key authentication
  66. local function authenticate()
  67. term.clear()
  68. drawBorder()
  69. centerText("Doggy OS Recovery key", 3)
  70.  
  71. if not verifyRecoveryKey() then
  72. os.reboot()
  73. end
  74. end
  75.  
  76. -- Start authentication process
  77. authenticate()
  78.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement