Guest User

partylegion

a guest
May 9th, 2016
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.82 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. -- [[ CENTER TEXT ]]
  3. function printcenter(sText)
  4.     local w, h = term.getSize()
  5.     local x, y = term.getCursorPos()
  6.     x = math.max(math.floor((w / 2) - (#sText / 2)), 0)
  7.     term.setCursorPos(x, y)
  8.     print(sText)
  9. end
  10.  
  11. -- [[ Login Func ]]
  12. function login()
  13.   term.clear()
  14.   term.setCursorPos(1,1)
  15.   printcenter("Please enter your details")
  16.   while true do
  17.     term.setCursorPos(1,3)
  18.     term.clearLine()
  19.         write("Username: ")
  20.         user = read()
  21.         if user == "" then
  22.  
  23.         elseif user == keyw then
  24.           term.setBackgroundColor(colors.black)
  25.           term.clear()
  26.           term.setCursorPos(1,1)
  27.           error()
  28.  
  29.         elseif user == username then break
  30.  
  31.   end
  32. end
  33.  
  34.   while true do
  35.     term.setCursorPos(1,5)
  36.         term.clearLine()
  37.         write("Password: ")
  38.         pass = read("*")
  39.         if pass == "" then
  40.  
  41.         elseif pass == keyw then
  42.  
  43.           term.setBackgroundColor(colors.black)
  44.           term.clear()
  45.           term.setCursorPos(1,1)
  46.           error()
  47.         elseif pass ~= keyw or password then break
  48.         elseif pass == password then break
  49.   end
  50. end
  51. -- [[ Accepting Password, Username ]]
  52.   if user == username and pass == password then
  53.     term.setCursorPos(1,7)
  54.         term.setTextColor(colors.red)
  55.         printcenter("Access granted.")
  56.         rs.setOutput(side,true)
  57.         sleep(3.5)
  58.         rs.setOutput(side,false)
  59.         os.reboot()
  60.   else
  61.         term.setCursorPos(1,7)
  62.         term.setTextColor(colors.red)
  63.         printcenter("Access denided.")
  64.         printcenter("Please try again.")
  65.         sleep(1.5)
  66.         os.reboot()
  67.   end
  68. end
  69.  
  70.  
  71.  
  72. -- [[ Saving Func ]]
  73. function save(name,input)
  74.   local file = fs.open("security/door/"..name,"w")
  75.   file.writeLine(input)
  76.   file.close()
  77. end
  78.  
  79. -- [[ Load Func ]]
  80. function load(fileName)
  81.   file = fs.open("security/door/"..fileName,"r")
  82.   local line = file.readLine()
  83.   file.close()
  84.   return line or "none"
  85. end
  86.  
  87. -- [[ Process func ]]
  88. function process()
  89.   term.setCursorPos(1,13)
  90.   printcenter("Processing your info, please wait.")
  91.   sleep(1.5)
  92.   term.setCursorPos(1,15)
  93.   printcenter("Processing your info, please wait..")
  94.   sleep(1.5)
  95.   term.setCursorPos(1,17)
  96.   printcenter("Done!")
  97.   sleep(1)
  98.   term.clear()
  99.   term.setCursorPos(1,4)
  100. -- [[ Display input ]]
  101.   print("              :------------------------:")
  102.   print("              : Username: "..usern)
  103.   print("              :                        ")
  104.   print("              : Password: "..passw)
  105.   print("              :                        ")
  106.   if keyw == "" then print("              : Code: NONE")
  107.   else print("              : Code: "..keyw)
  108.   end
  109.   print("              :                        ")
  110.   print("              : Side: "..side)
  111.   print("              :------------------------:")
  112.   print("")
  113.   print("              :---------:   :----------:")
  114.   print("              :Try again:   : Continue :")
  115.   print("              :---------:   :----------:")
  116.  
  117. -- [[ Buttons ]]
  118.   while true do
  119.     event, param, x,y = os.pullEvent("mouse_click")
  120.         if event == "mouse_click" and (x >= 16 and x <= 24) and y == 15 then os.reboot() -- Button 1.
  121.         elseif event == "mouse_click" and (x >= 30 and x <= 39) and y == 15 then -- Button 2.
  122.         fs.makeDir("security/door/")
  123.         save("info",usern) --Username
  124.         save("password",passw) --Password
  125.         save("side",side) --Door Side
  126.         if keyw == "" then
  127.           os.reboot()
  128.         else
  129.           save("keyw",keyw) --OS access code
  130.           os.reboot()
  131.   end
  132. end
  133. end
  134. end
  135.  
  136. -- [[ Checking for first run ]]
  137. if not term.isColor() then
  138.   print("Program requires an advanced computer.")
  139.   return
  140. end
  141.  
  142. term.setCursorPos(1,1)
  143. term.clear()
  144. term.setBackgroundColor(colors.black)
  145. term.setTextColor(colors.red)
  146. term.clear()
  147. if fs.exists("security/door/info") then
  148. else
  149.   term.setCursorPos(1,1)
  150.   printcenter("This is your first run")
  151.   term.setCursorPos(1,2)
  152.   printcenter(" Please make a new account.")
  153.   while true do
  154.     term.setCursorPos(1,4)
  155.         term.clearLine()
  156.         write("Enter your username: ")
  157.         usern = read()
  158.         if usern == "" then
  159.  
  160.         else
  161.           while true do
  162.             term.setCursorPos(1,6)
  163.             write("Enter your password: ")
  164.                 passw = read("*")
  165.                 if passw == "" then
  166.  
  167.                 elseif passw == usern then
  168.  
  169.                   term.setCursorPos(1,6)
  170.                   print("Password can't be same as username.")
  171.               sleep(1.5)
  172.                   term.setCursorPos(1,6)
  173.                   term.clearLine()
  174.                 else
  175.                   term.setCursorPos(1,8)
  176.                   write("Debug Password(blank for none): ")
  177.                   keyw = read()
  178.                   while true do
  179.                         term.setCursorPos(1,10)
  180.                         print("Please enter door side(right,left,bottom,top)")
  181.                         term.setCursorPos(1,11)
  182.                         term.clearLine()
  183.                         write("Side: ")
  184.                         side = read()
  185.                         if side == "" then  
  186.  
  187.                         elseif side == "right" then process()
  188.                         elseif side == "left" then process()
  189.                         elseif side == "bottom" then process()
  190.                         elseif side == "top" then process()
  191.  
  192.                         end
  193.                   end
  194.                 end
  195.       end
  196.         end
  197.   end
  198. end
  199.  
  200. -- [[ Run ]]
  201. os.pullEvent = os.pullEventRaw
  202. if fs.exists("security/door/keyw") then
  203.   keyw = load("keyw")
  204.   username = load("info")
  205.   password = load("password")
  206.   side = load("side")
  207.   login()
  208. else
  209.  
  210.   username = load("info")
  211.   password = load("password")
  212.   side = load("side")
  213.   login()
  214.  
  215. end
Add Comment
Please, Sign In to add comment