Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Function to draw a border around the screen
- local function drawBorder()
- term.clear()
- local w, h = term.getSize()
- for y = 1, h do
- term.setCursorPos(1, y)
- term.write("|")
- term.setCursorPos(w, y)
- term.write("|")
- end
- for x = 1, w do
- term.setCursorPos(x, 1)
- term.write("-")
- term.setCursorPos(x, h)
- term.write("-")
- end
- term.setCursorPos(1, 1)
- term.write("+")
- term.setCursorPos(w, 1)
- term.write("+")
- term.setCursorPos(1, h)
- term.write("+")
- term.setCursorPos(w, h)
- term.write("+")
- end
- -- Function to center text on the screen
- local function centerText(text, y)
- local w, _ = term.getSize()
- local x = math.floor((w - #text) / 2) + 1
- term.setCursorPos(x, y)
- term.write(text)
- end
- -- Function to verify user credentials
- local function verifyCredentials(username, password)
- local userPath = "/disk/users/" .. username
- if fs.exists(userPath .. "/admin.txt") and fs.exists(userPath .. "/password.txt") then
- local file = fs.open(userPath .. "/password.txt", "r")
- local storedPassword = file.readAll()
- file.close()
- return storedPassword == password
- end
- return false
- end
- -- Function to authenticate the user
- local function authenticate()
- term.clear()
- drawBorder()
- local _, h = term.getSize()
- centerText("Doggy OS UEFI Authentication", 3)
- local w, _ = term.getSize()
- local usernameX = math.floor(w / 2) - 10
- term.setCursorPos(usernameX, 5)
- term.write("Username: ")
- term.setCursorPos(usernameX + 10, 5)
- local username = read()
- term.setCursorPos(usernameX, 7)
- term.write("Password: ")
- term.setCursorPos(usernameX + 10, 7)
- local password = read("*") -- Masked input for password
- if verifyCredentials(username, password) then
- showMenu()
- else
- centerText("Invalid credentials. Access denied.", 10)
- os.sleep(2)
- -- Prompt if they have forgotten their password
- term.clear()
- drawBorder()
- centerText("Forgot your password? (Y/N)", math.floor(h / 2) + 2)
- term.setCursorPos(1, math.floor(h / 2) + 3)
- local response = string.lower(read())
- if response == "y" then
- recoveryKey() -- Call the function for recovery
- else
- os.reboot()
- end
- end
- end
- -- Function to show the recovery prompt
- local function recoveryKey()
- term.clear()
- drawBorder()
- local _, h = term.getSize()
- centerText("Password Recovery", math.floor(h / 2) - 2)
- local w, _ = term.getSize()
- local recoveryKeyX = math.floor(w / 2) - 10
- term.setCursorPos(recoveryKeyX, math.floor(h / 2))
- term.write("Enter recovery key: ")
- term.setCursorPos(recoveryKeyX + 20, math.floor(h / 2))
- local recoveryKey = read()
- if verifyRecoveryKey(recoveryKey) then
- centerText("Recovery successful.", math.floor(h / 2) + 1)
- os.sleep(2)
- -- Reset password or other actions
- showMenu() -- Call the menu if recovery was successful
- else
- centerText("Invalid recovery key.", math.floor(h / 2) + 1)
- os.sleep(2)
- os.reboot()
- end
- end
- -- Function to verify the recovery key
- local function verifyRecoveryKey(recoveryKey)
- local filePath = "/recovery/rckey.txt"
- if not fs.exists(filePath) then
- centerText("Recovery key file not found.", math.floor(h / 2) + 1)
- os.sleep(2)
- os.reboot()
- return false
- end
- local file = fs.open(filePath, "r")
- if not file then
- centerText("Error opening recovery key file.", math.floor(h / 2) + 1)
- os.sleep(2)
- os.reboot()
- return false
- end
- local storedKey = file.readAll()
- file.close()
- return storedKey == recoveryKey
- end
- -- Function to show UEFI options menu after successful authentication
- local function showMenu()
- term.clear()
- drawBorder()
- local _, h = term.getSize()
- centerText("Doggy OS UEFI Options", math.floor(h / 2) - 2)
- centerText("1. Recovery", math.floor(h / 2))
- centerText("2. Bootable devices", math.floor(h / 2) + 1)
- centerText("3. Shutdown", math.floor(h / 2) + 2)
- term.setCursorPos(1, math.floor(h / 2) + 3)
- term.write("Select an option: ")
- local choice = tonumber(read())
- if choice == 1 then
- -- Recovery
- shell.run("/disk/boot/Recovery.lua")
- elseif choice == 2 then
- -- Bootable devices (assuming this function exists)
- listBootableDevices()
- elseif choice == 3 then
- os.shutdown()
- else
- centerText("Invalid selection, rebooting.", math.floor(h / 2) + 4)
- os.sleep(2)
- os.reboot()
- end
- end
- -- Start the authentication process
- authenticate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement