Advertisement
Martmists

ComputerProtection.Lua

Apr 1st, 2015
486
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.40 KB | None | 0 0
  1. -- computer password protection with built-in password setup
  2.  
  3. local pullEvent = os.pullEvent -- stops people from using ctrl + t
  4. os.pullEvent = os.pullEventRaw -- ..
  5. local loop = true
  6. local Tries = 3 -- after this amount of tries the computer shuts down
  7. while loop do -- loop :)
  8.     term.clear()
  9.     term.setCursorPos(1,1)
  10.     if fs.exists("Password") then -- check if there is a password set already
  11.         file = io.open("Password", "r")
  12.         Password = file:read() -- get actual password
  13.         textutils.slowPrint("Enter password: ")
  14.         local Input = read("*")
  15.         if Input == Password then -- compare actual password to user input
  16.             textutils.slowPrint("Password correct.")
  17.             loop = false
  18.             os.pullEvent = pullEvent -- you can use ctrl + t if it crashed here
  19.         else -- password wrong
  20.             Tries = (Tries - 1) -- minus 1 try
  21.             textutils.slowPrint("Password incorrect.")
  22.             textutils.slowPrint("Tries left: ")
  23.             textutils.slowPrint(Tries)
  24.             if Tries == 0 then
  25.                 sleep(2)
  26.                 os.shutdown() -- reboot if tries = 0
  27.             end
  28.         end
  29.     else -- no password yet
  30.         textutils.slowPrint("Please choose a password:")
  31.         PasswordFile = read("*") -- type password
  32.         textutils.slowPrint("Password chosen: "..PasswordFile)
  33.         print("Do you want this password?") -- confirm
  34.         PasswordOK = read()
  35.         if PasswordOK == "Yes" then
  36.             file = io.open("Password", "w")
  37.             file:write(PasswordFile) -- store password
  38.             file:close()
  39.         end
  40.     end
  41. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement