-- client local validKeys = {} local users = { ["fatboychummy"] = { password = "SomeHashedPassword", balance = 64 } } while true do local senderID, message = rednet.receive("Banker") -- listens for rednet message with protocol "Banker" if type(message) == "table" then if message.action == "login" then if users[message.user] and users[message.user].password == message.password then -- login ok, return new key to user and save the login key local newKey = "blablabla" validKeys[newKey] = { expiry = os.clock() + 30 -- key valid for 30 seconds. user = users[message.user] } rednet.send(senderID, { ok = true, key = newKey }, "Banker") else -- login NOT okay, return failure rednet.send(senderID, { ok = false, error = "Login failure." }, "Banker") end else -- check valid key if validKeys[message.key] and validKeys[message.key].expiry > os.clock() then -- key valid if message.action == "getBalance" then rednet.send(senderID, { ok = true, balance = validKeys[message.key].user.balance }, "Banker") else -- invalid action rednet.send(senderID, { ok = false, error = "Invalid action: " .. message.action }, "Banker") end else -- key not valid rednet.send(senderID, { ok = false, error = "You are not logged in!" }, "Banker") end end end end