Advertisement
Guest User

startup

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