Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local SERVER_IP = "192.168.1.1" -- Replace with the actual server IP address
- local SERVER_PORT = 5000
- local MAX_ATTEMPTS = 3
- local DOMAIN_FILE = "/disk/domain.txt"
- local function drawPopupWindow(headerText, contentLines)
- term.clear()
- local w, h = term.getSize()
- local maxLength = #headerText
- for _, line in ipairs(contentLines) do
- maxLength = math.max(maxLength, #line)
- end
- local windowWidth = maxLength + 4
- local windowHeight = #contentLines + 4
- local xStart = math.floor(w / 2 - windowWidth / 2)
- local yStart = math.floor(h / 2 - windowHeight / 2)
- term.setCursorPos(xStart, yStart)
- term.write("+" .. string.rep("-", windowWidth - 2) .. "+")
- for i = 1, windowHeight - 2 do
- term.setCursorPos(xStart, yStart + i)
- term.write("|" .. string.rep(" ", windowWidth - 2) .. "|")
- end
- term.setCursorPos(xStart, yStart + windowHeight - 1)
- term.write("+" .. string.rep("-", windowWidth - 2) .. "+")
- term.setCursorPos(xStart + 2, yStart + 1)
- term.write(headerText)
- for i, line in ipairs(contentLines) do
- term.setCursorPos(xStart + 2, yStart + 1 + i + 1)
- term.write(line)
- end
- end
- local function authenticate(computerID, username, password)
- local socket = require("socket")
- local tcp = socket.tcp()
- tcp:connect(SERVER_IP, SERVER_PORT)
- tcp:send(computerID .. "\n")
- tcp:send(username .. "\n")
- tcp:send(password .. "\n")
- local response = tcp:receive()
- tcp:close()
- return response == "OK"
- end
- local function readDomainID()
- local domainFile = fs.open(DOMAIN_FILE, "r")
- local domainID = domainFile.readLine()
- domainFile.close()
- return domainID
- end
- local function drawLoginScreen(username, attemptsLeft)
- local contentLines = {
- "Username: " .. username,
- "Attempts left: " .. attemptsLeft,
- "",
- "Enter password:"
- }
- drawPopupWindow("Login to Doggy OS", contentLines)
- term.setCursorPos(math.floor(term.getSize() / 2) - 2, math.floor(term.getSize() / 2) + 1)
- end
- local function checkCredentials(username)
- local computerID = readDomainID()
- local attempts = 0
- repeat
- drawLoginScreen(username, MAX_ATTEMPTS - attempts)
- local enteredPassword = read("*")
- attempts = attempts + 1
- if authenticate(computerID, username, enteredPassword) then
- return true
- else
- drawPopupWindow("Access Denied", {"Incorrect password or Computer ID. Please try again."})
- os.sleep(2)
- end
- until attempts > MAX_ATTEMPTS
- drawPopupWindow("Account Disabled", {"Too many incorrect attempts. User has been disabled."})
- os.sleep(2)
- return false
- end
- local function main()
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- drawPopupWindow("Protected by Doggy OS Security", {"Enter username:"})
- local enteredUsername = read()
- if checkCredentials(enteredUsername) then
- drawPopupWindow("Welcome", {"Access granted. Welcome, " .. enteredUsername .. "!"})
- os.sleep(2)
- shell.run("/disk/os/gui")
- else
- drawPopupWindow("Access Denied", {"Access denied."})
- os.sleep(2)
- shell.run("/disk/os/lock.lua")
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement