Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local DOMAIN_FILE = "/.Domain_ID"
- local CACHED_USERS = "/disk/cached_users"
- -- Connect to Domain Controller
- local function connectToDomainController()
- if fs.exists(DOMAIN_FILE) then
- local file = fs.open(DOMAIN_FILE, "r")
- local domainID = file.readLine()
- file.close()
- return domainID
- else
- return nil
- end
- end
- -- Fetch user data from the domain controller
- local function fetchUserData(domainID)
- rednet.open("top") -- Adjust as per modem side
- rednet.send(domainID, textutils.serialize({type = "fetch_users"}))
- local _, message = rednet.receive()
- local userData = textutils.unserialize(message)
- rednet.close()
- -- Cache user data locally
- local file = fs.open(CACHED_USERS, "w")
- file.write(textutils.serialize(userData))
- file.close()
- end
- -- Validate login credentials
- local function validateCredentials(domainID, username, password)
- rednet.open("top")
- rednet.send(domainID, textutils.serialize({type = "authenticate", username = username, password = password}))
- local _, message = rednet.receive()
- rednet.close()
- local response = textutils.unserialize(message)
- return response.success, response.roles
- end
- -- Login process
- local function login()
- local domainID = connectToDomainController()
- if not domainID then
- print("Domain controller not found.")
- return
- end
- if not fs.exists(CACHED_USERS) then
- print("Fetching user data from the domain controller...")
- fetchUserData(domainID)
- end
- local file = fs.open(CACHED_USERS, "r")
- local cachedUsers = textutils.unserialize(file.readAll())
- file.close()
- print("Enter username:")
- local username = read()
- if not cachedUsers[username] then
- print("User not found.")
- return
- end
- print("Enter password:")
- local password = read("*")
- local success, roles = validateCredentials(domainID, username, password)
- if success then
- print("Login successful!")
- print("Roles: " .. table.concat(roles, ", "))
- -- Proceed to GUI or other functionality
- else
- print("Invalid credentials.")
- end
- end
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement