Advertisement
Guest User

startup

a guest
Nov 12th, 2017
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.57 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw -- This Does Not Allow You to CTRL+T
  2.  
  3. function clear()
  4.   term.clear()
  5.   term.setCursorPos(1,1)
  6. end
  7.  
  8. Sides = {"left", "right", "top", "bottom", "front", "back"}
  9.  
  10. for i = 1, #Sides do
  11.   rs.setOutput(Sides[i], false)
  12. end
  13.  
  14. ----------------------
  15. -- Use              --
  16. -- User: ADMIN      --
  17. -- Password: ADMIN  --
  18. --                  --
  19. -- To exit program  --
  20. ----------------------
  21. -- To Create A User --
  22. -- Go to Login      --
  23. -- Screen and type  --
  24. -- createaccount    --
  25. -- for the username --
  26. -- and leave the    --
  27. -- password blank   --
  28. -- and it will open --
  29. -- a UI to create   --
  30. -- a new account    --
  31. ----------------------
  32. -- config.cfg setup --
  33. -- Locked?          --
  34. -- MaxTries         --
  35. -- Door Time        --
  36. -- Door Side        --
  37. ----------------------
  38.  
  39.  
  40.  
  41. --if Ch == nil then
  42.   --Ch = 0
  43. --end
  44.  
  45.  
  46.  
  47. -- password = "super"
  48. -- Side = "left"
  49. -- Sec = 5
  50. -- MaxTries = 5
  51.  
  52. function login()
  53.   clear()
  54.   -- print("You have used "..Ch.."/"..MaxTries.." tries")
  55.   write("Username: ")
  56.   User = read()
  57.   -- print()
  58.   write("Enter Password: ")
  59.   input = read("*")
  60.   if User ~= "ADMIN" and input ~= "ADMIN" and User ~= "createaccount" then
  61.     checkUser(User, input)
  62.   elseif User == "ADMIN" and input == "ADMIN" then
  63.     error()
  64.   elseif User == "createaccount" then
  65.     clear()
  66.     print("Welcome to the account creation interface")
  67.     print("Please Fill out The Following Information")
  68.     write("Username: ")
  69.     User = read()
  70.     write("Password: ")
  71.     Pass = read("*")
  72.     write("Confirm Password: ")
  73.     CPass = read("*")
  74.     if Pass ~= CPass then  
  75.       print("The Two Passwords Don't Match Resetting")
  76.       login()      
  77.     else
  78.       ca = fs.open("acc/"..User, "w")
  79.       ca.write(Pass.."\n".."0")
  80.       ca.close()
  81.     end
  82.   end
  83.  
  84.   login()
  85. if false then  
  86.   if input == password then
  87.     rs.setOutput(Side, true)
  88.     clear()
  89.     print("Welcome User!")
  90.     sleep(Sec)
  91.     rs.setOutput(Side, false)
  92.     Ch = 0
  93.   else
  94.     Ch = Ch + 1
  95.     clear()
  96.     textutils.slowPrint("Incorrect Password You Have "..Ch.."/"..MaxTries.." tries left")
  97.     if not checkTries(Ch) then
  98.       login()
  99.     end
  100.   end
  101. end  
  102. end
  103.  
  104. function checkTries(Tries)
  105.   Tries = tonumber(Tries)
  106.   if Tries >= MaxTries then
  107.     clear()
  108.     print("This Computer Is Locked Please Contact Your Admin")
  109.     up = fs.open("config.cfg", "w")
  110.     up.write("true")
  111.     up.close()
  112.     while true do
  113.       ce = read()
  114.       if string.lower(ce) == "reset md5 hash" then
  115.         break
  116.       end
  117.     end
  118.     Ch = 0
  119.     login()
  120.   else
  121.     return false
  122.   end
  123. end
  124.  
  125. function checkUser(N, P)
  126.   -- N = User Submitted Username
  127.   -- P = User Submitted Password
  128.   if fs.exists("acc/"..N) then
  129.     OP = fs.open("acc/"..N, "r")
  130.     -- Things = OP.readAll()
  131.     -- OP.close()
  132.     Pass = OP.readLine()
  133.     Ch = OP.readLine()
  134.     if P == Pass then
  135.       Chs = 0
  136.       OI = fs.open("acc/"..N,"w")
  137.       OI.write(P.."\n"..Chs)
  138.       OI.close()
  139.       rs.setOutput(Side, true)
  140.       print()
  141.       print("Welcome "..N)
  142.       sleep(Sec)
  143.       rs.setOutput(Side, false)
  144.       login()
  145.     else
  146.       clear()
  147.       Ch = tonumber(Ch)
  148.       Chs = Ch + 1
  149.       ff = fs.open("acc/"..N, "w")
  150.       ff.write(Pass.."\n"..Chs)
  151.       ff.close()
  152.       checkTries(Chs)
  153.       print("Incorrect Password You Have "..Chs.."/"..MaxTries.." left")
  154.       sleep(3)
  155.       login()
  156.     end
  157.   else
  158.     printError("Error: Account Does Not Exist")
  159.     sleep(5)
  160.     login()
  161.   end
  162. end
  163.  
  164. if not fs.exists("config.cfg") then
  165.   clear()
  166.   print("Hello Welcome To The Setup Guide")
  167.   print("What would you like the max tries to be?")
  168.   write("MaxTries: ")
  169.   Max = read()
  170.   print("How Long Should The Door Be Open")
  171.   write("Seconds: ")
  172.   Secs = read()
  173.   print("Which Side is the door on?")
  174.   tSide = string.lower(read())
  175.   print("If you would like to create an account")
  176.   print("On the account creation screen user username")
  177.   print("\"createaccount\" and leave the password blank")
  178.   print("To begin account creation")
  179.   print("Press Any Key To Continute")
  180.   sleep(1)
  181.   os.pullEvent("key")
  182.   po = fs.open("config.cfg", "w")
  183.   po.writeLine("false")
  184.   po.writeLine(Max)
  185.   po.writeLine(Secs)
  186.   po.writeLine(tSide)
  187.   po.close()
  188.   os.reboot()
  189. else
  190.   ip = fs.open("config.cfg", "r")
  191.   locked = ip.readLine()
  192.   MaxTries = tonumber(ip.readLine())
  193.   Sec = tonumber(ip.readLine())
  194.   Side = ip .readLine()
  195.   if locked == "true" then
  196.       ip.close()
  197.     checkTries(MaxTries)
  198.   else
  199.     login()
  200.   end
  201.  
  202. end
  203.  
  204. --if not checkTries(Ch) then
  205. --  login()
  206. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement