Advertisement
Guest User

auth

a guest
Dec 14th, 2018
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.67 KB | None | 0 0
  1. -- cs authentication
  2. -- prompt for login on startup
  3.  
  4. -- specify the authentication server
  5. local authServer = "empty"
  6.  
  7. -- specify the authentication protocol
  8. local authProtocol = "auth"
  9.  
  10. -- specify the local credentials
  11. local localuser = "admin"
  12. local localpass = "admin"
  13.  
  14. -- used to validate credentials with server
  15. function validateCredentialsRemote(user, pass)
  16.   -- detect and open modems
  17.   for k, v in pairs(redstone.getSides()) do
  18.    
  19.   end
  20. end
  21.  
  22. -- used to validate credentials locally
  23. function validateCredentialsLocal(user, pass)
  24.   if user == username and pass = password then
  25.     local valid = true
  26.   else
  27.     local valid = false
  28.   end
  29.  
  30.   return valid
  31. end
  32.  
  33. -- continuously check for logins
  34. while true do
  35.   -- clear the terminal
  36.   term.clear()
  37.   term.setCursorPos(1, 1)
  38.   -- print a welcome message
  39.   print("CS AUTH SCRIPT\n")
  40.  
  41.   -- prompt the user for a username and password
  42.   write("username> ")
  43.   local username = read()
  44.   write("password> ")
  45.   local password = read()
  46.   local credentials = {username, password}    
  47.  
  48.   -- check if the auth server is reachable
  49.   local serverid = rednet.lookup(authProtocol, authServer)
  50.   -- authenticate with the server if reachable
  51.   if serverid ~= nil then
  52.     print("Found")
  53.     local valid = validateCredentialsRemote(username, password)
  54.   -- authenticate locally if the server is not found  
  55.   else
  56.     print("Not found")
  57.     local valid = validateCredentialsLocal(username, password)    
  58.   end
  59.  
  60.   -- launch a shell if the credentials are valid
  61.   if valid == true then
  62.     shell.run("/rom/programs/shell")
  63.   else
  64.     print("\nInvalid credentials. Press any key to continue...")
  65.   end
  66. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement