Advertisement
djshadowxm81

ccLoginAuth

Mar 4th, 2015
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. os.pullEvent = os.pullEventRaw
  2. local auth_channel = 54321
  3. local reply_channel = 234
  4.  
  5. local authenticated = false
  6. while not authenticated do
  7.     term.clear()
  8.     term.setCursorPos(1,1)
  9.     print("scs.mtweather.mil")
  10.     print("Authorized Users Only")
  11.     print("Access Attempts are Logged")
  12.     print("What side is your wireless modem on: [left,right,top,back,bottom] ")
  13.     local mSide = read()
  14.  
  15.     if mSide == "left" or mSide == "right" then
  16.         local modem = peripheral.wrap(mSide)
  17.         modem.open(reply_channel)
  18.         modem.isOpen(reply_channel)
  19.     elseif mSide == ("top") or mSide == ("back") then
  20.         local modem = peripheral.wrap(mSide)
  21.         modem.open(reply_channel)
  22.         modem.isOpen(reply_channel)
  23.     elseif mSide == ("bottom") or mSide == ("front") then
  24.         local modem = peripheral.wrap(mSide)
  25.         modem.open(reply_channel)
  26.         modem.isOpen(reply_channel)
  27.     else
  28.         print("No modem on that side or none connected.")
  29.         sleep(2)
  30.         os.reboot()
  31.     end
  32.  
  33.     write("Username: ")
  34.     local username = read()
  35.     write("Password: ")
  36.     local password = read("*")
  37.    
  38.     local user_table = {["username"] = username, ["password"] = password}
  39.     modem.transmit(auth_channel, reply_channel, textutils.serialize(user_table))
  40.     local response = false
  41.     while not response do
  42.         local event, modem_side, sender, reply_channel, message = os.pullEvent("modem_message")
  43.         if reply_channel == auth_channel then
  44.             response = true
  45.             if message == "valid" then
  46.                 modem.closeAll()
  47.                 term.clear()
  48.                 term.setCursorPos(1,1)
  49.                 print("Welcome")
  50.                 authenticated = true
  51.     break
  52.             else
  53.                 modem.closeAll()
  54.                 print("Invalid Login")
  55.                 sleep(2)
  56.                 shell.run("Auth")
  57.             end
  58.         end
  59.     end
  60. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement