ChaddJackson12

Computer Lock

Sep 29th, 2012
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.86 KB | None | 0 0
  1. os.pullEvent = os.pullEventRaw
  2. -- Local Variables --
  3. local root = ".ComputerLock/Lock/"
  4.  
  5. -- Functions --
  6. --[[ Password ]]--
  7. function invalid()
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10.     print("Invalid Input!")
  11.     os.sleep(2)
  12.     os.reboot()
  13. end
  14.  
  15. function uninstall()
  16.     print("\nDo You Want To Uninstall ComputerLock? Yes / No")
  17.     write("\n> ")
  18.     local input = read()
  19.     if input == "Yes" or input == "yes" then
  20.         write("\nEnter Current Password: ")
  21.         local input = read("*")
  22.         pr = fs.open(root .. "password", "r")
  23.         Password = pr.readLine()
  24.         pr.close()
  25.         if input == Password then
  26.             fs.delete(".ComputerLock")
  27.             fs.delete("startup")
  28.             print("\nComputerLock Uninstalled!")
  29.             os.reboot()
  30.         else
  31.             print("\nIncorrect Password!")
  32.             os.sleep(2)
  33.             os.reboot()
  34.         end
  35.     elseif input == "No" or input == "no" then
  36.         os.reboot()
  37.     else
  38.         invalid()
  39.     end
  40. end
  41.  
  42. function reSetNewPass()
  43.     print("\nPasswords Do Not Match!")
  44.     os.sleep(2)
  45.     setNewPass()
  46. end
  47.  
  48. function setNewPass()
  49.     write("\nEnter New Password: ")
  50.     NewPass = read("*")
  51.     write("Confirm New Password: ")
  52.     ConfirmNewPass = read("*")
  53.     if NewPass == ConfirmNewPass then
  54.         fs.delete(root .. "password")
  55.         pw = fs.open(root .. "password", "w")
  56.         pw.writeLine(ConfirmNewPass)
  57.         pw.close()
  58.         print("\nNew Password Set!")
  59.         os.sleep(2)
  60.         login()
  61.     else
  62.         reSetNewPass()
  63.     end
  64. end
  65.  
  66. function changePass()
  67.     print("\nDo You Want To Change The Password? Yes / No")
  68.     write("\n> ")
  69.     local input = read()
  70.     if input == "Yes" or input == "yes" then
  71.         write("\nEnter Current Password: ")
  72.         local input = read("*")
  73.         pr = fs.open(root .. "password", "r")
  74.         Password = pr.readLine()
  75.         pr.close()
  76.         if input == Password then
  77.             setNewPass()
  78.         else
  79.             print("\nIncorrect Password!")
  80.             os.sleep(2)
  81.             os.reboot()
  82.         end
  83.     elseif input == "No" or input == "no" then
  84.         os.reboot()
  85.     else
  86.         invalid()
  87.     end
  88. end
  89.  
  90. function reSetPass()
  91.     print("\nPasswords Do Not Match!")
  92.     os.sleep(2)
  93.     setPass()
  94. end
  95.  
  96. function setPass()
  97.     fs.makeDir(".ComputerLock")
  98.     fs.makeDir(".ComputerLock/Lock")
  99.     write("\nPlease Enter Your Password: ")
  100.     local PassEnter = read("*")
  101.     write("Please Confirm Your Password: ")
  102.     local PassConfirm = read("*")
  103.     if PassEnter == PassConfirm then
  104.         pw = fs.open(root .. "password", "w")
  105.         pw.write(PassConfirm)
  106.         pw.close()
  107.         print("\nPassword Has Been Set!")
  108.         os.sleep(2)
  109.         login()
  110.     else
  111.         reSetPass()
  112.     end
  113. end
  114.  
  115. function prolong()
  116.     print("\nOk")
  117.     os.sleep(1)
  118.     print("\nExiting ComputerLock")
  119.     os.sleep(2)
  120.     term.clear()
  121.     term.setCursorPos(1,1)
  122.     print("CraftOS")
  123.     return
  124. end
  125.  
  126. function correctPass()
  127. print("\nCorrect Password!")
  128. os.sleep(2)
  129. term.clear()
  130. term.setCursorPos(1,1)
  131. print("CraftOS")
  132. return
  133. end
  134.  
  135. function incorrectPass()
  136. print("\nIncorrect Password!")
  137. os.sleep(1)
  138. os.reboot()
  139. end
  140.  
  141. function reLogin()
  142.     login()
  143. end
  144.  
  145. function login()
  146.     term.clear()
  147.     term.setCursorPos(1,1)
  148.     print("ComputerLock 2.0")
  149.     print("\nThis Computer Is Locked!")
  150.     print("Press [Enter] To Unlock!")
  151.     repeat
  152.         event, key = os.pullEvent("key")
  153.         os.sleep(0.1)
  154.     until key == 28 or key == 210 or key == 211
  155.         if key == 28 then
  156.             write("\nEnter The Password: ")
  157.             local input = read("*")
  158.             pr = fs.open(root .. "password", "r")
  159.             Password = pr.readLine()
  160.             pr.close()
  161.             if input == Password then
  162.                 correctPass()
  163.             else
  164.                 incorrectPass()
  165.             end
  166.         elseif key == 210 then
  167.             changePass()
  168.         elseif key == 211 then
  169.             uninstall()
  170.         end
  171. end
  172.  
  173. -- Main --
  174. term.clear()
  175. term.setCursorPos(1,1)
  176. if fs.exists(root .. "password") then
  177.     login()
  178. elseif not fs.exists(root .. "password") then
  179.     print("Your ComputerLock Password Has Not Been Set!")
  180.     os.sleep(1)
  181.     print("\nWould You Like To Set It Now? Yes / No")
  182.     write("\n> ")
  183.     local input = read()
  184.     if input == "Yes" or input == "yes" then
  185.         setPass()
  186.     elseif input == "No" or input == "no" then
  187.         prolong()
  188.     else
  189.         invalid()
  190.     end
  191. end
Advertisement
Add Comment
Please, Sign In to add comment