Advertisement
DOGGYWOOF

Untitled

Oct 14th, 2024 (edited)
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. -- Disable default event handling to prevent termination
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. -- Hashing function to securely hash passwords
  5. local function hashPassword(password)
  6. local hash = 0
  7. for i = 1, #password do
  8. hash = (hash + password:byte(i) * i) % 1000003 -- Simple hash function
  9. end
  10. return tostring(hash)
  11. end
  12.  
  13. -- Function to read the password from the file
  14. local function readPassword()
  15. if not fs.exists("password.txt") then
  16. return nil
  17. end
  18.  
  19. local file = fs.open("password.txt", "r") -- Open the password file for reading
  20. local storedHash = file.readAll() -- Read the hashed password
  21. file.close()
  22. return storedHash -- Return the hashed password
  23. end
  24.  
  25. -- Function to save the new hashed password
  26. local function savePassword(newPassword)
  27. local file = fs.open("password.txt", "w") -- Open file for writing
  28. local hashedPassword = hashPassword(newPassword) -- Hash the new password
  29. file.write(hashedPassword) -- Save the hashed password
  30. file.close()
  31. end
  32.  
  33. -- Function to delete the startup file
  34. local function deleteStartup()
  35. local startupPath = "/startup" -- Path to the startup file
  36. if fs.exists(startupPath) then
  37. fs.delete(startupPath) -- Deletes the file
  38. return true
  39. else
  40. return false
  41. end
  42. end
  43.  
  44. -- Function to draw the GUI
  45. local function drawGUI()
  46. term.clear()
  47. term.setBackgroundColor(colors.black)
  48. term.setTextColor(colors.white)
  49.  
  50. -- Title
  51. term.setCursorPos(1, 1)
  52. term.write("=== Doggy OS Tamper Protection Service ===")
  53.  
  54. -- Instructions
  55. term.setCursorPos(1, 3)
  56. term.write("Please enter the password to proceed:")
  57.  
  58. -- Password Input
  59. term.setCursorPos(1, 5)
  60. term.write("Password: ")
  61. end
  62.  
  63. -- Function to handle reboot
  64. local function reboot()
  65. term.setCursorPos(1, 9)
  66. term.write("Rebooting...") -- Indicate that the system is rebooting
  67. sleep(2) -- Wait for 2 seconds before reboot
  68. os.reboot() -- Reboot the system
  69. end
  70.  
  71. -- Main function
  72. local function main()
  73. drawGUI() -- Draw the GUI
  74.  
  75. local storedHash = readPassword() -- Read the hashed password
  76. if not storedHash then
  77. -- If the password file doesn't exist, ask for a new password
  78. term.setCursorPos(1, 5)
  79. term.write("Password: ")
  80. local newPassword = read("*") -- Get the new password
  81. savePassword(newPassword) -- Save the new password
  82. term.setCursorPos(1, 7)
  83. term.write("New password saved.")
  84. sleep(2) -- Pause before rebooting
  85. reboot() -- Reboot the system after saving
  86. else
  87. term.setCursorPos(1, 5)
  88. term.write("Password: ") -- Redraw prompt for password input
  89. local enteredPassword = read("*") -- Use read("*") to mask input
  90.  
  91. -- Hash the entered password for comparison
  92. local enteredHash = hashPassword(enteredPassword)
  93.  
  94. -- Check if the entered hash matches the stored hash
  95. if enteredHash == storedHash then
  96. if deleteStartup() then
  97. term.setCursorPos(1, 7)
  98. term.write("File '/startup' deleted successfully.")
  99. else
  100. term.setCursorPos(1, 7)
  101. term.write("Error: '/startup' not found.")
  102. end
  103. sleep(2) -- Pause to allow user to read the message
  104. reboot() -- Call the reboot function after a pause
  105. else
  106. term.setCursorPos(1, 7)
  107. term.write("Incorrect password.")
  108. sleep(2) -- Pause before rebooting
  109. reboot() -- Reboot on incorrect password
  110. end
  111. end
  112. end
  113.  
  114. -- Execute the main function
  115. main()
  116.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement