Advertisement
Virgilcore

vault door password

Nov 23rd, 2024 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.80 KB | Cybersecurity | 0 0
  1. --[[
  2.   Password Lock Program for OpenComputers
  3.  
  4.  
  5.   This program is designed to run indefinitely on a basic terminal to provide
  6.   password protection via redstone. It includes configurations for the door open
  7.   duration, redstone output side, password, and an "admin" break password that will
  8.   allow a user to gracefully terminate the program.
  9.  
  10.  
  11.   By badcode9, 2016
  12. ]]
  13.  
  14. local component = require("component")
  15.  
  16. if not component.isAvailable("redstone") then
  17.   io.stderr:write("This program requires either a Redstone Card Tier 1 or Redstone I/O block to run.\n")
  18.   return
  19. end
  20. local rs = component.redstone
  21.  
  22. local os = require("os")
  23. local term = require("term")
  24. local text = require("text")
  25. local sides = require("sides")
  26.  
  27.  
  28.  
  29.  
  30. --[[ Config ]]-----------------------------------------------------------------
  31. local pass = "2056"
  32. local d = 5 -- Door open duration
  33. local s = sides.bottom -- Where to output redstone signal to open the door
  34.  
  35. --[[ Door Control ]]-----------------------------------------------------------
  36. local function openDoor(duration)
  37.   -- Open door for the duration provided, then close again.
  38.   rs.setOutput(s, 15)
  39.   os.sleep(duration)
  40.   rs.setOutput(s, 0)
  41. end
  42.  
  43. --[[ Main ]]-------------------------------------------------------------------
  44.  
  45. -- Close door on init
  46. rs.setOutput(s, 0)
  47.  
  48. while true do
  49.  term.clear()
  50.  
  51.  -- Password Request
  52.  print("Enter Password:")
  53.  answer = text.trim(term.read(nil, false, nil, "*"))  -- Masking input characters; trim newline
  54.  term.setCursor(1,2)
  55.  term.clearLine()
  56.  
  57.  -- Password Check
  58.  if answer == "REDadmin" then -- admin pwd to break execution
  59.   term.clear()
  60.   print("Admin Override\n")
  61.   return
  62.  elseif answer == pass then
  63.    print("ACCESS GRANTED")
  64.    openDoor(d)
  65.  else
  66.    print("ACCESS DENIED")
  67.    os.sleep(3)
  68.  end
  69. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement