Advertisement
DOGGYWOOF

Untitled

Nov 27th, 2024 (edited)
4
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. local DOMAIN_FILE = "/.Domain_ID"
  2. local CACHED_USERS = "/disk/cached_users"
  3.  
  4. -- Connect to Domain Controller
  5. local function connectToDomainController()
  6. if fs.exists(DOMAIN_FILE) then
  7. local file = fs.open(DOMAIN_FILE, "r")
  8. local domainID = file.readLine()
  9. file.close()
  10. return domainID
  11. else
  12. return nil
  13. end
  14. end
  15.  
  16. -- Fetch user data from the domain controller
  17. local function fetchUserData(domainID)
  18. rednet.open("top") -- Adjust as per modem side
  19. rednet.send(domainID, textutils.serialize({type = "fetch_users"}))
  20. local _, message = rednet.receive()
  21. local userData = textutils.unserialize(message)
  22. rednet.close()
  23.  
  24. -- Cache user data locally
  25. local file = fs.open(CACHED_USERS, "w")
  26. file.write(textutils.serialize(userData))
  27. file.close()
  28. end
  29.  
  30. -- Validate login credentials
  31. local function validateCredentials(domainID, username, password)
  32. rednet.open("top")
  33. rednet.send(domainID, textutils.serialize({type = "authenticate", username = username, password = password}))
  34. local _, message = rednet.receive()
  35. rednet.close()
  36.  
  37. local response = textutils.unserialize(message)
  38. return response.success, response.roles
  39. end
  40.  
  41. -- Login process
  42. local function login()
  43. local domainID = connectToDomainController()
  44. if not domainID then
  45. print("Domain controller not found.")
  46. return
  47. end
  48.  
  49. if not fs.exists(CACHED_USERS) then
  50. print("Fetching user data from the domain controller...")
  51. fetchUserData(domainID)
  52. end
  53.  
  54. local file = fs.open(CACHED_USERS, "r")
  55. local cachedUsers = textutils.unserialize(file.readAll())
  56. file.close()
  57.  
  58. print("Enter username:")
  59. local username = read()
  60. if not cachedUsers[username] then
  61. print("User not found.")
  62. return
  63. end
  64.  
  65. print("Enter password:")
  66. local password = read("*")
  67. local success, roles = validateCredentials(domainID, username, password)
  68.  
  69. if success then
  70. print("Login successful!")
  71. print("Roles: " .. table.concat(roles, ", "))
  72. -- Proceed to GUI or other functionality
  73. else
  74. print("Invalid credentials.")
  75. end
  76. end
  77.  
  78. login()
  79.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement