Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ The Magic Config ]]--
- local password = "password"
- -- Place your password here
- local master_password = "master password"
- -- Place your master password here
- local lock_door = false
- -- This locks doors... dunno what else you could say about that...
- local max_attempts = 3
- -- Set the max number of "guesses" a player can make before it locks
- -- Set this to -1 for infinite guesses
- local case_sensitive = false
- -- Set this to true if you want exact passwords
- -- If password is "password", "PasSwOrd" will be denied.
- --[[ The Magical Lock ]]--
- os.pullEvent = os.pullEventRaw
- --[[ Tables ]]--
- local tArgs = { ... }
- --[[ Functions ]]--
- function cs()
- term.clear()
- term.setCursorPos(1, 1)
- end
- function screen()
- cs()
- local mx, my = term.getSize()
- if term.isColor() then
- term.setTextColor(colors.cyan)
- end
- for a=1, 3 do
- for b=1, mx do
- write("+")
- end
- if a == 1 then
- term.setCursorPos(1, 3)
- elseif a == 2 then
- term.setCursorPos(1, my)
- end
- end
- term.setCursorPos(1, my-1)
- if term.isColor() then
- term.setTextColor(colors.lime)
- end
- write("Attempts Left: ")
- if term.isColor() then
- term.setTextColor(colors.red)
- end
- if attempts then
- if attempts == -1 then
- write("Infinite")
- else
- write(attempts)
- end
- else
- attempts = max_attempts
- write(attempts)
- end
- term.setCursorPos(1, 2)
- if term.isColor() then
- term.setTextColor(colors.lime)
- end
- centerT("RandomSecurity")
- end
- function centerT(text)
- mx, my = term.getSize()
- cx, cy = term.getCursorPos()
- term.setCursorPos(math.floor((mx-string.len(text))/2), cy)
- write(text)
- end
- function split(s,re)
- local i1 = 1
- local ls = {}
- local append = table.insert
- if not re then
- re = '%s+'
- end
- if re == '' then
- return {s}
- end
- while true do
- local i2,i3 = s:find(re,i1)
- if not i2 then
- local last = s:sub(i1)
- if last ~= '' then
- append(ls,last)
- end
- if #ls == 1 and ls[1] == '' then
- return {}
- else
- return ls
- end
- end
- append(ls,s:sub(i1,i2-1))
- i1 = i3+1
- end
- end
- function centerST(text)
- mx, my = term.getSize()
- if not pocket then
- term.setCursorPos(math.ceil((mx-string.len(text))/2), my/2+0.5)
- write(text)
- else
- nString = split(text)
- strHalf = math.floor(#nString / 2)
- local pocketUPos = 0
- for i=1, strHalf do
- pocketUPos = pocketUPos + string.len(nString[i])
- end
- term.setCursorPos(math.floor((mx-pocketUPos)/2), my/2-1)
- for i=1, strHalf do
- write(nString[i].." ")
- end
- local pocketDPos = 1
- for i=strHalf+1, #nString do
- pocketDPos = pocketDPos + string.len(nString[i])
- end
- term.setCursorPos(math.floor((mx-pocketDPos)/2), my/2+1)
- for i=strHalf+1, #nString do
- write(nString[i].." ")
- end
- end
- end
- --[[ Main ]]--
- if #tArgs > 0 then
- if string.lower(tArgs[1]) == "save" or "disk" then
- cs()
- textutils.slowPrint("Saving to disk...")
- local sides = rs.getSides()
- for i=1, #sides do
- if disk.isPresent(sides[i]) then
- cs()
- print("Saving file to "..sides[i].." drive")
- fs.copy(shell.getRunningProgram(), "disk/startup")
- end
- end
- end
- sleep(1.5)
- os.reboot()
- end
- screen()
- centerST("Press ENTER to continue")
- local event, key = os.pullEvent("key")
- if key then
- while true do
- cs()
- screen()
- term.setCursorPos(1, 5)
- centerT("Enter Password")
- term.setCursorPos(3, 7)
- input = read("*")
- if not case_sensitive then
- input = string.lower(input)
- password = string.lower(password)
- master_password = string.lower(master_password)
- end
- if input == password then
- sleep(1)
- cs()
- screen()
- centerST("Password Accepted!")
- sleep(2)
- if not lock_door then
- cs()
- break
- else
- centerST("Opening door...")
- local sides = rs.getSides()
- for i=1, #sides do
- rs.setOutput(sides[i], true)
- sleep(4)
- rs.setOutput(sides[i], false)
- end
- cs()
- end
- elseif input == master_password and lock_door then
- sleep(1)
- cs()
- screen()
- centerST("Door lock terminated")
- sleep(2)
- cs()
- break
- else
- attempts = attempts - 1
- cs()
- screen()
- term.setCursorPos(1, 5)
- centerT("Password Incorrect!")
- if attempts == 0 then
- cs()
- centerST("You have no attempts left!")
- sleep(10)
- os.reboot()
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment