Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- cs authentication
- -- prompt for login on startup
- -- specify the authentication server details
- authServer = "none"
- authProtocol = "auth"
- -- specify the local credentials
- localuser = "admin"
- localpass = "admin"
- -- used to validate credentials with server
- function validateCredentialsRemote(id, user, pass)
- -- detect and open modems
- for k, v in pairs(redstone.getSides()) do
- if peripheral.getType(v) == "modem" then
- rednet.open(v)
- end
- end
- -- send the credentials to the authentication server
- local credentials = {user, pass}
- rednet.send(id, credentials, authProtocol)
- -- receive a message from the server
- local source, message = rednet.receive(authProtocol, 10)
- if source == id and message == "SUCCESS" then
- return true
- elseif source == id and message == "FAILURE" then
- return false, "Invalid credentials."
- else
- return false, "Could not connect to the server."
- end
- end
- -- used to validate credentials locally
- function validateCredentialsLocal(user, pass)
- if user == localuser and pass == localpass then
- return true
- else
- return false, "Invalid credentials."
- end
- end
- -- continuously check for logins
- while true do
- -- clear the terminal
- term.clear()
- term.setCursorPos(1, 1)
- -- print a welcome message
- print("PROPERTY OF CS FACTION\n")
- -- prompt the user for a username and password
- write("username> ")
- local user = read()
- write("password> ")
- local pass = read()
- -- validate with a remote server or locally
- local valid, e
- -- use the authentication server if specified
- if authServer ~= "none" then
- -- lookup the id of the authentication server
- local id = rednet.lookup(authProtocol, authServer)
- -- validate using the authentication server
- if id ~= nil then
- print("\nConnecting to authentication server...")
- valid, e = validateCredentialsRemote(id, user, pass_
- else
- print("\nAuthentication server not found. Using local credentials...")
- valid, e = validateCredentialsLocal(user, pass)
- end
- -- use local credentials if an authentication server is not specified
- else
- valid, e = validateCredentialsLocal(user, pass)
- end
- -- launch a shell if the credentials are valid
- if valid == true then
- term.clear()
- term.setCursorPos(1, 1)
- shell.run("/rom/programs/shell")
- else
- print(e.." Press any key to continue...")
- read()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement