extremeGEgaming

Password lock alpha version

Jun 23rd, 2014
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.99 KB | None | 0 0
  1. function changerecoveryid() --Change id of the computer for the ftp recovery
  2. --needs to be implemented
  3. end
  4.  
  5. function ftprecovery() --Ftp recovery of password using the ftp id
  6. --needs to be implemented
  7. end
  8.  
  9. function changesafety() --Change safety code password
  10. --Needs to be tested
  11. term.clear()
  12. term.setCursorPos(1,1)
  13. write("New safety code: ")
  14. newpass = read("*")
  15. term.clear()
  16. term.setCursorPos(1,1)
  17. while true do
  18. term.clear()
  19. term.setCursorPos(1,1)
  20. write("Confirm code: ")
  21. confirm = read("*")
  22. if newpass == confirm then
  23. file = fs.open("login/safety","w")
  24. file.write(newpass)
  25. file.close()
  26. print("Password set..")
  27. sleep(2)
  28. term.clear()
  29. term.setCursorPos(1,1)
  30. break
  31. elseif newpass == "" then
  32. term.clear()
  33. term.setCursorPos(1,1)
  34. break
  35. else
  36. term.clear()
  37. term.setCursorPos(1,1)
  38. write("Confirmation failed. Please try again.")
  39. sleep(1)
  40. end
  41. end
  42. --Needs to be tested
  43. end
  44.  
  45. function changepass() --Change password function
  46. --Needs to be tested
  47. term.clear()
  48. term.setCursorPos(1,1)
  49. write("New password: ")
  50. newpass = read("*")
  51. term.clear()
  52. term.setCursorPos(1,1)
  53. while true do
  54. term.clear()
  55. term.setCursorPos(1,1)
  56. write("Confirm password: ")
  57. confirm = read("*")
  58. if newpass == confirm then
  59. file = fs.open("login/password","w")
  60. file.write(newpass)
  61. file.close()
  62. print("Password set..")
  63. sleep(2)
  64. term.clear()
  65. term.setCursorPos(1,1)
  66. break
  67. elseif newpass == "" then
  68. term.clear()
  69. term.setCursorPos(1,1)
  70. break
  71. else
  72. term.clear()
  73. term.setCursorPos(1,1)
  74. write("Confirmation failed. Please try again.")
  75. sleep(1)
  76. end
  77. end
  78. --Needs to be tested
  79. end
  80.  
  81. --The logged function (deletes .blocked, .nsafety, and resets attempts) and opens main control menu
  82. function logged()
  83. while true do
  84. fs.delete("login/.blocked")
  85. fs.delete("login/.nsafety")
  86. file = fs.open("login/attempt","w")
  87. file.write("0")
  88. file.close()
  89. term.clear()
  90. term.setCursorPos(1,1)
  91. print("Welcome!")
  92. print("1: Login")
  93. print("2: Change password")
  94. print("3: Change safety code")
  95. print("4: Change default computer id for pass recovery")
  96. choice = read()
  97. if choice == 1 then
  98. error()
  99. elseif choice == 2 then
  100. changepass()
  101. elseif choice == 3 then
  102. changesafety()
  103. elseif choice == 4 then
  104. changerecoveryid()
  105. end
  106. end
  107. end
  108.  
  109. function first() --First time setup
  110. term.clear()
  111. term.setCursorPos(1,1)
  112. print("This is the first time you login!")
  113. sleep(2)
  114. term.clear()
  115. term.setCursorPos(1,1)
  116. print("Please enter your password")
  117. sleep(2)
  118. changepass()
  119. file = fs.open("login/.nft","w")
  120. file.close()
  121. term.clear()
  122. sleep(1)
  123. term.clear()
  124. term.setCursorPos(1,1)
  125. print("Please enter your safety code")
  126. sleep(2)
  127. changesafety()
  128. sleep(1)
  129. term.clear()
  130. term.setCursorPos(1,1)
  131. print("Please enter your remote recovery computer id")
  132. sleep(2)
  133. changerecoveryid()
  134. term.clear()
  135. term.setCursorPos(1,1)
  136. textutils.slowPrint("Initializing...")
  137. sleep(1)
  138. end
  139.  
  140. --The unblocking function (deletes .blocked, .nsafety, and resets attempts)
  141. function unblock()
  142. fs.delete("login/.blocked")
  143. fs.delete("login/.nsafety")
  144. file = fs.open("login/attempt","w")
  145. file.write("0")
  146. file.close()
  147. term.clear()
  148. term.setCursorPos(1,1)
  149. print("Terminal unblocked! :D")
  150. sleep(2)
  151. end
  152.  
  153. --The blocking function
  154. function block()
  155. while true do
  156. file = fs.open("login/.blocked","w")
  157. file.close()
  158. term.clear()
  159. term.setCursorPos(1,1)
  160. print("Terminal blocked!")
  161. print("1: Safety code (works only once and only one attempt)") --Safety code unblocks the system once
  162. print("2: Send bypass code to default computer") --Bypass code sent to default listed computer Bypasses the password and lets you change it (if the feature is enabled)
  163. print("Enter your option below:")
  164. choice = read()
  165. if choice == 1 then
  166.     if not fs.exists("login/.nsafety") and fs.exists("login/safety") then
  167.         file = fs.open("login/safety","r")
  168.         correctsafecode = file.readAll()
  169.         file.close()
  170.         inputedsafecode = read("*")
  171.         if inputedsafecode == correctsafecode then
  172.         unblock()
  173.         return
  174.     else
  175.         file = fs.open("login/.nsafety","w")
  176.         file.close()
  177.     end
  178.     end
  179.     if not fs.exists("login/safety") then
  180.     term.clear()
  181.     term.setCursorPos(1,1)
  182.     print("Safety code was not set or deleted..")
  183.     sleep(2)
  184.     end
  185.     if fs.exists("login/.nsafety") then
  186.     term.clear()
  187.     term.setCursorPos(1,1)
  188.     print("Safety code was already entered..")
  189.     sleep(2)
  190.     end
  191. elseif choice == 2 then
  192. ftprecovery()
  193. --needs to be implemented
  194. elseif choice ~= 1 or choice ~= 2 then
  195. print("Incorrect choice")
  196. sleep(1)
  197. end
  198. end
  199. end
  200.  
  201. function check()
  202.     if fs.exists("login/.blocked") then block() end --Retains the block session
  203.     if fs.exists("login/.nlocking") then --Checks if locking feature is on or off and also force repair .nft and attempts files
  204.     lock = 0
  205.     file = fs.open("login/attempt","w")
  206.     file.write("0")
  207.     file.close()
  208.     file = fs.open("login/.nft","w")
  209.     file.close()
  210.     return 0
  211. else
  212. lock = 1
  213. --Checking password files and .nft data (the data that shows if the user is logging in for the first time)
  214. --And blocks and repair them and restore defaults if needed
  215. if not fs.exists("login/.nft") and fs.exists("login/password") then
  216.     file = fs.open("login/.nft","w")
  217.     file.close()
  218.     end
  219. if not fs.exists("login/.nft") and not fs.exists("login/password") then
  220.     first()
  221.     end
  222. if fs.exists("login/.nft") and not fs.exits("login/password") then --Attempt to call nil!? ;(
  223.     file = fs.open("login/.nft","w")
  224.     file.close()
  225.     term.clear()
  226.     term.setCursorPos(1,1)
  227.     print("Password was deleted or corrupted!")
  228.     sleep(2)
  229.     block()
  230.     end
  231. --Checking the attempts and maxattempts files and blocks and repair them and restore defaults if needed
  232. if not fs.exists("login/attempt") and fs.exists("login/.nft") then
  233. file = fs.open("login/attempt","w")
  234.     file.write("0")
  235.     file.close()
  236.     print("Attempts file was deleted or corrupted!")
  237.     sleep(2)
  238.     block()
  239.     end
  240. if not fs.exists("login/attempt") and not fs.exists("login/.nft") then
  241. file = fs.open("login/attempt","w")
  242.     file.write("0")
  243.     file.close()
  244.     end
  245. if not fs.exists("login/maxattempt") and not fs.exists("login/.nft") then
  246. file = fs.open("login/attempt","w")
  247.     file.write("3")
  248.     file.close()
  249.     end
  250. if not fs.exists("login/maxattempt") and fs.exists("login/.nft") then
  251. file = fs.open("login/attempt","w")
  252.     file.write("3")
  253.     file.close()
  254.     print("Maxattempts file was deleted or corrupted!")
  255.     sleep(2)
  256.     block()
  257.     end
  258. --Read attempts and maxattempts from file
  259. file = fs.open("login/attempt","r")
  260. attempts = file.readAll()
  261. file.close()
  262. file = fs.open("login/maxattempt","r")
  263. maxattempts = file.readAll()
  264. file.close()
  265. end
  266. end
  267.  
  268. --Counts attempts and blocks if limit exceeded
  269. function attempts()
  270. attempts = attempts + 1
  271. if attempts >= maxattempts then
  272.     print("You exceeded the attempts limit!")
  273.     sleep(2)
  274.     block()
  275.     end
  276. end
  277. --Main part of the program
  278. while true do
  279. check()
  280. if lock == 1 then
  281.     term.clear()
  282.     term.setCursorPos(1,1)
  283.     print("")
  284.     print("Terminal locked")
  285.     print("")
  286.     write("Password: ")
  287.     file = fs.open("login/password","r")
  288.     correctpass = file.readAll()
  289.     file.close()
  290.     pass = read("*")
  291.     if pass == correctpass then logged()
  292.     else
  293.     attempts()
  294.     end
  295. end
  296. end
Advertisement
Add Comment
Please, Sign In to add comment