Inumel

login

May 21st, 2013
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.02 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 denied()
  28.  write("Incorrect username or password ")
  29.  textutils.slowWrite("Shutting down...")
  30.  sleep(1)
  31. end  
  32.  
  33. local function admin()
  34. os.pullEvent = oldPull
  35.   term.clear()
  36.   term.setCursorPos(1,1)
  37.   term.setTextColor(colors.cyan)
  38.   print("Welcome "..name.."!")
  39.   term.setTextColor(colors.white)
  40.   print("Type options for a list of options!")
  41.   op = read()
  42.  
  43.   if op == "options" then
  44.     term.setTextColor(colors.red)
  45.     for k,v in pairs(options) do print(v) end
  46.     term.setTextColor(colors.white)
  47.     print("make a selection")
  48.     cp = read()
  49.     if table_contains(options,cp) then
  50.       if cp == "test" then
  51.         print("test")
  52.       end
  53.       if cp == "butts" then
  54.         print("test2")
  55.       end
  56.       if cp == "reserved" then
  57.         print("Exiting..")
  58.         sleep(2)
  59.         os.reboot()
  60.      
  61.      
  62.      
  63.      
  64.     end
  65.    end
  66.    end
  67. end
  68. while true do
  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.     if name ~= names[1] or names[2] then
  83.     denied()
  84.     end
  85.   end
  86. if name == names[2] then
  87.   if passs == pass[2] then
  88.     admin()
  89.   end
  90. else
  91.   if name ~= names[1] or names[2] then
  92.     denied()
  93. end
  94. end
  95. end
  96. open.close()
  97. ps.close()
Advertisement
Add Comment
Please, Sign In to add comment