Advertisement
DOGGYWOOF

Untitled

Aug 28th, 2024
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. -- Server-side code to handle user authentication requests
  2.  
  3. local SERVER_PORT = 5000
  4. local USERS_FOLDER = "/disk/users/"
  5. local DOMAIN_FILE = "/disk/domain.txt"
  6.  
  7. local function handleClient(client)
  8. local computerID = client.read()
  9. local username = client.read()
  10. local password = client.read()
  11.  
  12. -- Check if the computer ID is valid
  13. local domainFile = fs.open(DOMAIN_FILE, "r")
  14. local allowedID = domainFile.readLine()
  15. domainFile.close()
  16.  
  17. if computerID ~= allowedID then
  18. client.write("FAIL")
  19. client.close()
  20. return
  21. end
  22.  
  23. -- Check user credentials
  24. local passwordFile = fs.combine(USERS_FOLDER .. username, "password.txt")
  25. if fs.exists(passwordFile) then
  26. local file = fs.open(passwordFile, "r")
  27. local storedPassword = file.readLine()
  28. file.close()
  29.  
  30. if password == storedPassword then
  31. client.write("OK")
  32. else
  33. client.write("FAIL")
  34. end
  35. else
  36. client.write("FAIL")
  37. end
  38.  
  39. client.close()
  40. end
  41.  
  42. local function startServer()
  43. local socket = require("socket")
  44. local server = socket.tcp()
  45. server:bind("*", SERVER_PORT)
  46. server:listen()
  47.  
  48. while true do
  49. local client = server:accept()
  50. parallel.waitForAny(
  51. function()
  52. handleClient(client)
  53. end
  54. )
  55. end
  56. end
  57.  
  58. startServer()
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement