Advertisement
Guest User

startup

a guest
Nov 12th, 2017
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.65 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.cp", "r")
  132.     text = up.readAll()
  133.     up.close()
  134.     textz = string.gsub(text, "false", "true")
  135.     up = fs.open("config.cfg", "w")
  136.     up.write(textz)
  137.     up.close()
  138.     while true do
  139.       ce = read()
  140.       if string.lower(ce) == "reset md5 hash" then
  141.         break
  142.       end
  143.     end
  144.     Ch = 0
  145.     login()
  146.   else
  147.     return false
  148.   end
  149. end
  150.  
  151. function checkUser(N, P)
  152.   -- N = User Submitted Username
  153.   -- P = User Submitted Password
  154.   if fs.exists("acc/"..N) then
  155.     OP = fs.open("acc/"..N, "r")
  156.     -- Things = OP.readAll()
  157.     -- OP.close()
  158.     Pass = OP.readLine()
  159.     Ch = OP.readLine()
  160.     if P == Pass then
  161.       Chs = 0
  162.       OI = fs.open("acc/"..N,"w")
  163.       OI.write(P.."\n"..Chs)
  164.       OI.close()
  165.       rs.setOutput(Side, true)
  166.       print()
  167.       print("Welcome "..N)
  168.       sleep(Sec)
  169.       rs.setOutput(Side, false)
  170.       login()
  171.     else
  172.       clear()
  173.       Ch = tonumber(Ch)
  174.       Chs = Ch + 1
  175.       ff = fs.open("acc/"..N, "w")
  176.       ff.write(Pass.."\n"..Chs)
  177.       ff.close()
  178.       checkTries(Chs)
  179.       print("Incorrect Password You Have "..Chs.."/"..MaxTries.." left")
  180.       sleep(3)
  181.       login()
  182.     end
  183.   else
  184.     printError("Error: Account Does Not Exist")
  185.     sleep(5)
  186.     login()
  187.   end
  188. end
  189.  
  190. if not fs.exists("config.cfg") then
  191.   clear()
  192.   print("Hello Welcome To The Setup Guide")
  193.   print("What would you like the max tries to be?")
  194.   write("MaxTries: ")
  195.   Max = read()
  196.   print("How Long Should The Door Be Open")
  197.   write("Seconds: ")
  198.   Secs = read()
  199.   while true do
  200.     print("Which Side is the door on?")
  201.     print("(right/left/top/bottom/front/back)")
  202.     tSide = string.lower(read())
  203.     for i = 1, #Sides do
  204.       if tSide == Sides[i] then
  205.         Conf = true
  206.       end
  207.     end
  208.     if Conf then
  209.       break
  210.     else
  211.       printError("Invalid Side")
  212.      
  213.     end
  214.   end
  215.   print()
  216.   print("If you would like to create an account")
  217.   print("On the account creation screen user username")
  218.   print("\"createaccount\" and leave the password blank")
  219.   print("To begin account creation")
  220.   print("Press Any Key To Continute")
  221.   sleep(1)
  222.   os.pullEvent("key")
  223.   po = fs.open("config.cfg", "w")
  224.   po.writeLine("false")
  225.   po.writeLine(Max)
  226.   po.writeLine(Secs)
  227.   po.writeLine(tSide)
  228.   po.close()
  229.   fs.copy("config.cfg", "config.cp")
  230.   os.reboot()
  231. else
  232.   ip = fs.open("config.cfg", "r")
  233.   locked = ip.readLine()
  234.   MaxTries = tonumber(ip.readLine())
  235.   Sec = tonumber(ip.readLine())
  236.   Side = ip .readLine()
  237.   if locked == "true" then
  238.       ip.close()
  239.     checkTries(MaxTries)
  240.   else
  241.     login()
  242.   end
  243.  
  244. end
  245.  
  246. --if not checkTries(Ch) then
  247. --  login()
  248. --end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement