Inumel

login

May 20th, 2013
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.92 KB | None | 0 0
  1. local oldPull = os.pullEvent
  2. os.pullEvent = os.pullEventRaw
  3.  
  4. local function loadTable(names)
  5. open = fs.open(tostring(names),"r")
  6. local nstr = open.readAll()
  7. local newtable = textutils.unserialize(nstr)
  8. return newtable
  9. end
  10. local function loadTablepass(pass)
  11. ps = fs.open(tostring(pass),"r")
  12. local num = ps.readAll()
  13. local newtablepass = textutils.unserialize(num)
  14. return newtablepass
  15. end
  16. local function table_contains(table,element)
  17.   for _,value in pairs(table) do
  18.     if value == element then
  19.       return true
  20.     end
  21.   end
  22. end
  23.   options = {"reserved",
  24.  -- "test",
  25.  -- "butts"
  26.  }
  27. local function fail()
  28.  write("Incorrect username or password ")
  29.  textutils.slowWrite("Shutting down...")
  30.  sleep(1)
  31.  os.reboot()
  32. end  
  33.  
  34. local function admin()
  35. os.pullEvent = oldPull
  36.   term.clear()
  37.   term.setCursorPos(1,1)
  38.   term.setTextColor(colors.cyan)
  39.   print("Welcome "..name.."!")
  40.   term.setTextColor(colors.white)
  41.   print("Type options for a list of options!")
  42.   op = read()
  43.  
  44.   if op == "options" then
  45.     term.setTextColor(colors.red)
  46.     for k,v in pairs(options) do print(v) end
  47.     term.setTextColor(colors.white)
  48.     print("make a selection")
  49.     cp = read()
  50.     if table_contains(options,cp) then
  51.       if cp == "test" then
  52.         print("test")
  53.       end
  54.       if cp == "butts" then
  55.         print("test2")
  56.       end
  57.       if cp == "reserved" then
  58.         print("Exiting..")
  59.         sleep(2)
  60.         os.reboot()
  61.      
  62.      
  63.      
  64.      
  65.     end
  66.    end
  67.    end
  68. end
  69. names = loadTable("names")
  70. pass = loadTablepass("pass")
  71. term.clear()
  72. term.setCursorPos(1,1)
  73. print("Please enter a staff ID!")
  74. name = read()
  75. print("Please enter your four digit passcode!")
  76. passs = read()
  77. if name == names[1] then
  78.   if passs == pass[1] then
  79.     admin()
  80.   end
  81.   else
  82.     fail()
  83.   end
  84. if name == names[2] then
  85.   if passs == pass[2] then
  86.     admin()
  87.   end
  88.   else
  89.     fail()
  90. end
  91. open.close()
  92. ps.close()
Advertisement
Add Comment
Please, Sign In to add comment