Advertisement
Guest User

startup

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