Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Password Lock Program for OpenComputers
- This program is designed to run indefinitely on a basic terminal to provide
- password protection via redstone. It includes configurations for the door open
- duration, redstone output side, password, and an "admin" break password that will
- allow a user to gracefully terminate the program.
- By badcode9, 2016
- ]]
- local component = require("component")
- if not component.isAvailable("redstone") then
- io.stderr:write("This program requires either a Redstone Card Tier 1 or Redstone I/O block to run.\n")
- return
- end
- local rs = component.redstone
- local os = require("os")
- local term = require("term")
- local text = require("text")
- local sides = require("sides")
- --[[ Config ]]-----------------------------------------------------------------
- local pass = "2056"
- local d = 5 -- Door open duration
- local s = sides.bottom -- Where to output redstone signal to open the door
- --[[ Door Control ]]-----------------------------------------------------------
- local function openDoor(duration)
- -- Open door for the duration provided, then close again.
- rs.setOutput(s, 15)
- os.sleep(duration)
- rs.setOutput(s, 0)
- end
- --[[ Main ]]-------------------------------------------------------------------
- -- Close door on init
- rs.setOutput(s, 0)
- while true do
- term.clear()
- -- Password Request
- print("Enter Password:")
- answer = text.trim(term.read(nil, false, nil, "*")) -- Masking input characters; trim newline
- term.setCursor(1,2)
- term.clearLine()
- -- Password Check
- if answer == "REDadmin" then -- admin pwd to break execution
- term.clear()
- print("Admin Override\n")
- return
- elseif answer == pass then
- print("ACCESS GRANTED")
- openDoor(d)
- else
- print("ACCESS DENIED")
- os.sleep(3)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement