Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Encrypted password lock door. Uses valithor's tiny hashing algorithm.
- -- pastebin get uW0X4aKn lock
- --os.pullEvent = os.pullEventRaw --THIS IS DONE FOR A REASON. DO NOT UNCOMMENT.
- local doorSide = {} --If it is to side(s), then it will open a door.
- local doorCorrectDelay = 6 --How long the door is open after getting it right
- local doorIncorrectDelay = 2 --How long you are locked out for getting it wrong
- local doorInvertRedstone = false --Inverts redstone for door locks that require it.
- local passwordFile = "/.lddlock"
- local saltCode = tostring(os.getComputerID()^2)
- local palate
- if not term.isColor() then
- if _VERSION then
- palate = {
- bgcolor = colors.gray, --Background color
- fgcolor = colors.lightGray, --Foreground color
- bg_txtcolor = colors.white, --Text color when overlayed on bgcolor
- fg_txtcolor = colors.black, --Text color when overlayed on fgcolor
- bgcorrect = colors.white, --Background color when correct.
- bgincorrect = colors.black, --Background color when incorrect.
- txtcorrect = colors.gray, --Text color when correct.
- txtincorrect = colors.gray, --Text color when incorrect.
- }
- else
- palate = {
- bgcolor = colors.black, --Background color
- fgcolor = colors.white, --Foreground color
- bg_txtcolor = colors.white, --Text color when overlayed on bgcolor
- fg_txtcolor = colors.black, --Text color when overlayed on fgcolor
- bgcorrect = colors.white, --Background color when correct.
- bgincorrect = colors.black, --Background color when incorrect.
- txtcorrect = colors.black, --Text color when correct.
- txtincorrect = colors.white, --Text color when incorrect.
- }
- end
- else
- palate = {
- bgcolor = colors.gray, --Background color
- fgcolor = colors.lightGray, --Foreground color
- bg_txtcolor = colors.white, --Text color when overlayed on bgcolor
- fg_txtcolor = colors.black, --Text color when overlayed on fgcolor
- bgcorrect = colors.green, --Background color when correct.
- bgincorrect = colors.red, --Background color when incorrect.
- txtcorrect = colors.white, --Text color when correct.
- txtincorrect = colors.black, --Text color when incorrect.
- }
- end
- for a = 1, #doorSide do
- redstone.setOutput(doorSide[a], doorInvertRedstone)
- end
- local function clearLines(top, bottom)
- for a = top, bottom do
- term.setCursorPos(1,a)
- term.clearLine()
- end
- end
- local function hash(msg,salt,bool)
- if not bool then
- for i = 1, 10 do
- msg = hash(msg,salt or "",true)
- end
- end
- local num = ""
- local salt = salt ~= nil and salt..msg or msg
- for i = 1, #salt do
- local let = salt:sub(i,i):byte()
- num = let <= 9 and num.."99"..let or let<=99 and num.."9"..let or num..let
- end
- math.randomseed(tonumber(num))
- local hashed = ""
- for i = 1, 250 do
- hashed = hashed..string.char(math.random(32,127))
- end
- return hashed
- end
- local function rollOver(input, max)
- return math.floor(input % max)
- end
- local number
- local function flashScreen(times, number)
- local flashes
- if term.isColor() then
- flashes = {
- colors.white,
- colors.black,
- colors.red,
- }
- else
- if _CC_VERSION then
- flashes = {
- colors.white,
- colors.black,
- colors.lightGray,
- }
- else
- flashes = {
- colors.white,
- colors.black,
- }
- end
- end
- local terminateMessages = {
- "TERMINATE AGAIN, I DARE YOU",
- "TERMINATE AGAIN, I DARE YOU",
- "NO PLEASE, I IMPLORE",
- "NO, REALLY",
- "MOST PEOPLE DISABLE TERMINATION...",
- "BUT THAT'S BORING.",
- "THIS IS AT LEAST FUNNY!",
- "I MEAN, YOU DIDN'T EXPECT MULTIPLE MESSAGES",
- "AT LEAST, I DON'T THINK...",
- "...",
- "OKAY, THIS IS GETTING OLD FAST",
- "STOP IT!",
- "STOP TERMINATING, OR ERRORING, OR WHATEVER",
- "I'LL TELL THE ADMIN!",
- "I WILL!",
- "I'M WARNING YOU!",
- ".....",
- "...YOU CALLED MY BLUFF.",
- "OKAY, I CAN DO SOMETHING THAT YOU WON'T LIKE",
- "NO, IT'S NOT TO TATTLE TO A MODERATOR...",
- "IT'S SOMETHING MUCH WORSE.",
- "OKAY NOT REALLY, UNLESS YOU HAVE EPILEPSY",
- "AREN'T YOUR FINGERS GETTING TIRED?",
- "I GUESS NOT...?",
- "OKAY, HERE IT GOES!",
- "YOU'D BETTER HEED MY WARNING!",
- "<<flash>>",
- "WHAT DID I TELL YOU?",
- "YOU THOUGHT YOU'D CALL MY BLUFF, BUT NOOOOO",
- "YOU MUST THINK YOU'RE SOOOOO CLEVER",
- "BUT LOOKIT YOU NOW! ALL DEAD AND STUFF",
- "....",
- "...OKAY, I'M GETTING BORED.",
- "ACTUALLY, I WAS ALREADY BORED...",
- "BUT I THOUGHT THIS WOULD BE FUN",
- "HOW WRONG WAS I?",
- "ANYHOW, JUST...UM...",
- "...DO WHATEVER IT IS YOU DO",
- "WHEN YOU'RE NOT DESTROYING THE FACILITY",
- "YOU SHOULD PLAY PORTAL NOW.",
- "IT'S MUCH MORE FUN THAN TERMINATING A LOCK.",
- "BELIEVE ME, YOU'LL HAVE A GREAT TIME DOING THAT",
- "...",
- "......",
- "OKAY, IF YOU'RE DOING THIS TO FIND OUT THE CODE...",
- "...OR GAIN ACCESS WITHOUT IT...",
- "...THEN YOU ARE WASTING YOUR TIME.",
- "THIS USES HASHING. THE PASSWORD ISN'T STORED...",
- "...IN PLAIN TEXT, THAT IS",
- "IF YOU WANT THAT, THEN GO BEG THE OWNER FOR IT",
- "AND BY THAT I MEAN THE OWNER OF THE COMPUTER",
- "NOT THE GUY WHO WROTE THE LOCK",
- "I'M SURE HE HAS BETTER THINGS TO DO THAN THIS.",
- "THIS IS THE LAST LINE OF DIALOGUE.",
- "THIS IS THE LAST LINE OF DIALOGUE.",
- "THIS IS THE LAST LINE OF DIALOGUE.",
- "THIS IS THE LAST LINE OF DIALOGUE.",
- "THIS IS TOTALLY THE LAST LINE OF DIALOGUE.",
- "GOD DAMN IT, MAN!",
- "YOU WANT ACCESS SO BAD?",
- "YOU DO?",
- "<<flash>>",
- "NOW YOU HAVE ACCESS TO THE FLOOR",
- "DON'T BREAK IT, FATTY",
- "OH, I'M SORRY...",
- "I ONLY SAID THAT BECAUSE...",
- "YOU LOOK LIKE YOU'RE SMUGGLING A CAR",
- "STUPID. STUPID FATTY.",
- "...",
- "*ROBOTIC COUGH*",
- "Damn is this script long!",
- "I can't wait until someone mods this and adds their own!",
- "Welp, I'm not adding anything else.",
- "Really, the last message will repeat.",
- "So, my ultimate message is:",
- "DO NOT TERMINATE.",
- } --THAT was a mouthful!
- if not number then
- number = 1
- end
- if number >= #terminateMessages then
- number = #terminateMessages
- end
- local message = terminateMessages[number]
- local scr_x, scr_y = term.getSize()
- if message == "<<flash>>" then
- for a = 1, 64 do
- sleep(0)
- if term.isColor() then
- term.setBackgroundColor(2^math.random(0,15))
- else
- if a % 2 == 0 then
- term.setBackgroundColor(colors.white)
- else
- term.setBackgroundColor(colors.black)
- end
- end
- term.clear()
- end
- else
- for a = 1, times do
- for b = 1, #flashes do
- term.setBackgroundColor(flashes[b])
- term.setTextColor(flashes[rollOver(b+1,#flashes)+1])
- term.clear()
- scr_x, scr_y = term.getSize()
- if #message >= scr_x then
- term.setCursorPos(1,scr_y/2)
- else
- term.setCursorPos(math.ceil(scr_x/2)-math.floor(#message/2),scr_y/2)
- end
- write(message)
- sleep(0)
- end
- end
- end
- end
- local terminateCount = 1
- local isCurrentlyGood = false
- local function handleCrash(results)
- if not isCurrentlyGood then
- term.clear()
- term.setCursorBlink(false)
- local oldpullevent = os.pullEvent
- os.pullEvent = os.pullEventRaw
- flashScreen(10, terminateCount) --Gotta rub it in, man.
- os.pullEvent = oldpullevent
- terminateCount = terminateCount + 1
- term.setCursorBlink(true)
- return false
- else
- return true
- end
- end
- local function cprint(txt)
- local scr_x, scr_y = term.getSize()
- local posX, posY = term.getCursorPos()
- term.setCursorPos(math.ceil(scr_x/2)-math.ceil(#txt/2),posY)
- return print(txt)
- end
- local function writeConfig(password, overwrite)
- if overwrite then
- file = fs.open(passwordFile,"w")
- else
- file = fs.open(passwordFile,"a")
- end
- file.writeLine(password)
- file.close()
- end
- local function choice(filter, verbose)
- if verbose == true then
- write("[")
- for a = 1, #filter do
- write(string.upper(string.sub(filter,a,a)))
- if a ~= #filter then
- write(",")
- end
- end
- write("]?")
- end
- local event, key
- repeat
- event, key = os.pullEvent("char")
- until string.find(filter,key)
- if verbose then
- write(string.upper(key))
- end
- return key, string.find(filter,key)
- end
- local function correctPassword()
- term.setBackgroundColor(palate.bgcorrect)
- term.setTextColor(palate.txtcorrect)
- local scr_x, scr_y = term.getSize()
- term.setCursorPos(1,scr_y)
- if #doorSide > 0 then
- isCurrentlyGood = true
- end
- for a = 2, scr_y do
- sleep(0)
- term.scroll(1)
- if a == math.ceil(scr_y/2) then
- cprint("Correct!")
- end
- end
- if #doorSide > 0 then
- term.setCursorPos(1,math.floor(scr_y/2)+1)
- cprint("Applying RS to "..table.concat(doorSide,", "))
- for a = 1, #doorSide do
- redstone.setOutput(doorSide[a], not doorInvertRedstone)
- end
- if type(doorCorrectDelay) == "number" then
- sleep(doorCorrectDelay)
- else
- sleep(6)
- end
- isCurrentlyGood = false
- for a = 1, #doorSide do
- redstone.setOutput(doorSide[a], doorInvertRedstone)
- end
- return
- else
- sleep(0.6)
- if _VERSION then
- term.setCursorPos(1,scr_y/2)
- term.setTextColor(colors.lightGray)
- term.setBackgroundColor(colors.lightGray)
- term.clear()
- cprint("Correct!")
- sleep(0)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.gray)
- term.clear()
- sleep(0)
- end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- return true
- end
- end
- local function incorrectPassword(pswd)
- term.setBackgroundColor(palate.bgincorrect)
- term.setTextColor(palate.txtincorrect)
- local scr_x, scr_y = term.getSize()
- term.clear()
- term.setCursorPos(1,scr_y/2)
- if string.lower(pswd) == "bepis" then
- cprint("Bepis.")
- else
- cprint("WRONG.")
- end
- if type(doorIncorrectDelay) == "number" then
- sleep(doorIncorrectDelay)
- else
- sleep(2)
- end
- end
- local function gui()
- scr_x, scr_y = term.getSize()
- while true do
- term.setBackgroundColor(palate.bgcolor)
- term.setTextColor(palate.bg_txtcolor)
- term.clear()
- term.setCursorPos(1,3)
- cprint("Password:")
- local posX, posY = term.getCursorPos()
- term.setBackgroundColor(palate.fgcolor)
- term.setTextColor(palate.fg_txtcolor)
- local password
- repeat
- term.setCursorPos(1,posY)
- term.clearLine()
- write(">")
- password = read("*")
- until string.gsub(password," ","") ~= ""
- local hashpassword = hash(password,saltCode)
- term.setBackgroundColor(palate.fgcolor)
- term.setTextColor(palate.fg_txtcolor)
- local file = fs.open(passwordFile,"r")
- local a, correct = nil, false
- repeat
- a = file.readLine()
- if a == hashpassword then
- if correctPassword() == true then
- correct = true
- return true
- end
- end
- until not a
- if not correct then
- incorrectPassword(password)
- end
- end
- end
- if not fs.exists(passwordFile) then
- term.setBackgroundColor(palate.bgcolor)
- term.setTextColor(palate.bg_txtcolor)
- term.clear()
- term.setCursorPos(1,2)
- cprint("No password file!")
- local newpassword, confpassword
- repeat
- repeat
- cprint("Enter a new password.")
- local posX, posY = term.getCursorPos()
- term.setBackgroundColor(palate.fgcolor)
- term.setTextColor(palate.fg_txtcolor)
- repeat
- term.setCursorPos(1,posY)
- term.clearLine()
- write(">")
- newpassword = read("*")
- until string.gsub(newpassword," ","") ~= ""
- term.setBackgroundColor(palate.bgcolor)
- term.setTextColor(palate.bg_txtcolor)
- cprint("Confirm that.")
- local posX, posY = term.getCursorPos()
- term.setBackgroundColor(palate.fgcolor)
- term.setTextColor(palate.fg_txtcolor)
- repeat
- term.setCursorPos(1,posY)
- term.clearLine()
- write(">")
- confpassword = read("*")
- until string.gsub(confpassword," ","") ~= ""
- term.setBackgroundColor(palate.bgcolor)
- term.setTextColor(palate.bg_txtcolor)
- if newpassword ~= confpassword then
- cprint("They don't match!")
- local posX, posY = term.getCursorPos()
- posY = posY + 1
- end
- until newpassword == confpassword
- writeConfig(hash(newpassword,saltCode), false)
- cprint("Wrote! Do another password?")
- local input = choice("yn",true)
- until input == "n"
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1,1)
- cprint("Got it, man.")
- cprint("Run again to start the lock.")
- return true
- end
- while true do
- status, res = pcall(gui)
- if not status then
- local a = handleCrash(res)
- if a then
- return true
- end
- else
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement