Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Disable default event handling to prevent termination
- os.pullEvent = os.pullEventRaw
- -- Hashing function to securely hash passwords
- local function hashPassword(password)
- local hash = 0
- for i = 1, #password do
- hash = (hash + password:byte(i) * i) % 1000003 -- Simple hash function
- end
- return tostring(hash)
- end
- -- Function to read the password from the file
- local function readPassword()
- if not fs.exists("password.txt") then
- return nil
- end
- local file = fs.open("password.txt", "r") -- Open the password file for reading
- local storedHash = file.readAll() -- Read the hashed password
- file.close()
- return storedHash -- Return the hashed password
- end
- -- Function to save the new hashed password
- local function savePassword(newPassword)
- local file = fs.open("password.txt", "w") -- Open file for writing
- local hashedPassword = hashPassword(newPassword) -- Hash the new password
- file.write(hashedPassword) -- Save the hashed password
- file.close()
- end
- -- Function to delete the startup file
- local function deleteStartup()
- local startupPath = "/startup" -- Path to the startup file
- if fs.exists(startupPath) then
- fs.delete(startupPath) -- Deletes the file
- return true
- else
- return false
- end
- end
- -- Function to draw the GUI
- local function drawGUI()
- term.clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- -- Title
- term.setCursorPos(1, 1)
- term.write("=== Doggy OS Tamper Protection Service ===")
- -- Instructions
- term.setCursorPos(1, 3)
- term.write("Please enter the password to proceed:")
- -- Password Input
- term.setCursorPos(1, 5)
- term.write("Password: ")
- end
- -- Function to handle reboot
- local function reboot()
- term.setCursorPos(1, 9)
- term.write("Rebooting...") -- Indicate that the system is rebooting
- sleep(2) -- Wait for 2 seconds before reboot
- os.reboot() -- Reboot the system
- end
- -- Main function
- local function main()
- drawGUI() -- Draw the GUI
- local storedHash = readPassword() -- Read the hashed password
- if not storedHash then
- -- If the password file doesn't exist, ask for a new password
- term.setCursorPos(1, 5)
- term.write("Password: ")
- local newPassword = read("*") -- Get the new password
- savePassword(newPassword) -- Save the new password
- term.setCursorPos(1, 7)
- term.write("New password saved.")
- sleep(2) -- Pause before rebooting
- reboot() -- Reboot the system after saving
- else
- term.setCursorPos(1, 5)
- term.write("Password: ") -- Redraw prompt for password input
- local enteredPassword = read("*") -- Use read("*") to mask input
- -- Hash the entered password for comparison
- local enteredHash = hashPassword(enteredPassword)
- -- Check if the entered hash matches the stored hash
- if enteredHash == storedHash then
- if deleteStartup() then
- term.setCursorPos(1, 7)
- term.write("File '/startup' deleted successfully.")
- else
- term.setCursorPos(1, 7)
- term.write("Error: '/startup' not found.")
- end
- sleep(2) -- Pause to allow user to read the message
- reboot() -- Call the reboot function after a pause
- else
- term.setCursorPos(1, 7)
- term.write("Incorrect password.")
- sleep(2) -- Pause before rebooting
- reboot() -- Reboot on incorrect password
- end
- end
- end
- -- Execute the main function
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement