jille_Jr icon

CC: Security #1 password

jille_Jr | PRO | 10/09/12 05:37:16 PM UTC | 0 ⭐ | 430 👁️ | Never ⏰ | []
Lua |

910 B

|

None

|

0 👍

/

0 👎

-- Security #1
-- Password lock
-- Code written by jag_e_nummer_ett
 
local oldPull = os.pullEvent;
os.pullEvent = os.pullEventRaw;
 
function login()
  local password = "password"
  local inputPass = ""
  local tries = 5
  while inputPass ~= password do
    term.clear()
    if tries < 5 then
      term.setCursorPos(3,5)
      print("Incorrect password!")
    end
    term.setCursorPos(3,2)
    print("Please enter password")
    term.setCursorPos(3,4)
    print("Tries left: "..tries)
    term.setCursorPos(3,3)
    write("Password: ")
    inputPass = read("*")
    tries = tries - 1
    if tries == 0 then
      return false
    end
  end
  return true
end
 
if login() then
  term.clear()
  term.setCursorPos(3,2)
  print("Login successful!")
  sleep(1.5)
else
  term.clear()
  term.setCursorPos(3,2)
  print("Login failed!")
  sleep(1.5)
  os.shutdown()
end
 
os.pullEvent = oldPull;

Comments