Advertisement
DOGGYWOOF

Untitled

Aug 28th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. local SERVER_IP = "192.168.1.1" -- Replace with the actual server IP address
  2. local SERVER_PORT = 5000
  3. local MAX_ATTEMPTS = 3
  4. local DOMAIN_FILE = "/disk/domain.txt"
  5.  
  6. local function drawPopupWindow(headerText, contentLines)
  7. term.clear()
  8. local w, h = term.getSize()
  9. local maxLength = #headerText
  10. for _, line in ipairs(contentLines) do
  11. maxLength = math.max(maxLength, #line)
  12. end
  13.  
  14. local windowWidth = maxLength + 4
  15. local windowHeight = #contentLines + 4
  16. local xStart = math.floor(w / 2 - windowWidth / 2)
  17. local yStart = math.floor(h / 2 - windowHeight / 2)
  18.  
  19. term.setCursorPos(xStart, yStart)
  20. term.write("+" .. string.rep("-", windowWidth - 2) .. "+")
  21. for i = 1, windowHeight - 2 do
  22. term.setCursorPos(xStart, yStart + i)
  23. term.write("|" .. string.rep(" ", windowWidth - 2) .. "|")
  24. end
  25. term.setCursorPos(xStart, yStart + windowHeight - 1)
  26. term.write("+" .. string.rep("-", windowWidth - 2) .. "+")
  27.  
  28. term.setCursorPos(xStart + 2, yStart + 1)
  29. term.write(headerText)
  30.  
  31. for i, line in ipairs(contentLines) do
  32. term.setCursorPos(xStart + 2, yStart + 1 + i + 1)
  33. term.write(line)
  34. end
  35. end
  36.  
  37. local function authenticate(computerID, username, password)
  38. local socket = require("socket")
  39. local tcp = socket.tcp()
  40. tcp:connect(SERVER_IP, SERVER_PORT)
  41. tcp:send(computerID .. "\n")
  42. tcp:send(username .. "\n")
  43. tcp:send(password .. "\n")
  44. local response = tcp:receive()
  45. tcp:close()
  46. return response == "OK"
  47. end
  48.  
  49. local function readDomainID()
  50. local domainFile = fs.open(DOMAIN_FILE, "r")
  51. local domainID = domainFile.readLine()
  52. domainFile.close()
  53. return domainID
  54. end
  55.  
  56. local function drawLoginScreen(username, attemptsLeft)
  57. local contentLines = {
  58. "Username: " .. username,
  59. "Attempts left: " .. attemptsLeft,
  60. "",
  61. "Enter password:"
  62. }
  63. drawPopupWindow("Login to Doggy OS", contentLines)
  64. term.setCursorPos(math.floor(term.getSize() / 2) - 2, math.floor(term.getSize() / 2) + 1)
  65. end
  66.  
  67. local function checkCredentials(username)
  68. local computerID = readDomainID()
  69. local attempts = 0
  70. repeat
  71. drawLoginScreen(username, MAX_ATTEMPTS - attempts)
  72. local enteredPassword = read("*")
  73. attempts = attempts + 1
  74. if authenticate(computerID, username, enteredPassword) then
  75. return true
  76. else
  77. drawPopupWindow("Access Denied", {"Incorrect password or Computer ID. Please try again."})
  78. os.sleep(2)
  79. end
  80. until attempts > MAX_ATTEMPTS
  81. drawPopupWindow("Account Disabled", {"Too many incorrect attempts. User has been disabled."})
  82. os.sleep(2)
  83. return false
  84. end
  85.  
  86. local function main()
  87. term.setTextColor(colors.white)
  88. term.setBackgroundColor(colors.black)
  89. term.clear()
  90.  
  91. drawPopupWindow("Protected by Doggy OS Security", {"Enter username:"})
  92. local enteredUsername = read()
  93.  
  94. if checkCredentials(enteredUsername) then
  95. drawPopupWindow("Welcome", {"Access granted. Welcome, " .. enteredUsername .. "!"})
  96. os.sleep(2)
  97. shell.run("/disk/os/gui")
  98. else
  99. drawPopupWindow("Access Denied", {"Access denied."})
  100. os.sleep(2)
  101. shell.run("/disk/os/lock.lua")
  102. end
  103. end
  104.  
  105. main()
  106.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement