Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- computer password protection with built-in password setup
- local pullEvent = os.pullEvent -- stops people from using ctrl + t
- os.pullEvent = os.pullEventRaw -- ..
- local loop = true
- local Tries = 3 -- after this amount of tries the computer shuts down
- while loop do -- loop :)
- term.clear()
- term.setCursorPos(1,1)
- if fs.exists("Password") then -- check if there is a password set already
- file = io.open("Password", "r")
- Password = file:read() -- get actual password
- textutils.slowPrint("Enter password: ")
- local Input = read("*")
- if Input == Password then -- compare actual password to user input
- textutils.slowPrint("Password correct.")
- loop = false
- os.pullEvent = pullEvent -- you can use ctrl + t if it crashed here
- else -- password wrong
- Tries = (Tries - 1) -- minus 1 try
- textutils.slowPrint("Password incorrect.")
- textutils.slowPrint("Tries left: ")
- textutils.slowPrint(Tries)
- if Tries == 0 then
- sleep(2)
- os.shutdown() -- reboot if tries = 0
- end
- end
- else -- no password yet
- textutils.slowPrint("Please choose a password:")
- PasswordFile = read("*") -- type password
- textutils.slowPrint("Password chosen: "..PasswordFile)
- print("Do you want this password?") -- confirm
- PasswordOK = read()
- if PasswordOK == "Yes" then
- file = io.open("Password", "w")
- file:write(PasswordFile) -- store password
- file:close()
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement