Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
thedukeofcrawley

Password door

Question

Hi guys i have a question for you,

 

i have used a program of the forum and changed it a little bit and its working fine, but i cant get the password hidden with *

i tried the pwchar but the it will not start anymore, and also how do i start it upon boot?

The pwchar parameter, when given, 
causes input to be masked using the first char of the given string. For example, providing "*" will make all entered characters appear as stars. 
The returned value will still be the actual text inserted, of course.

i hope one of you guys can help me or implement it in the code i use

 

Here is the code

local component=require("component")
local r=component.redstone
local gpu=component.gpu
local term=require("term")


---- config section
local password="ucisrrc876"
local delay=1 --time the door stays open
local side=5 --side of the door, test this
-----


local wrong=false


while true do
  term.clear()
  gpu.set(1,1,"UCIS Rocket Control Centre")
  term.setCursor(1,2)
  gpu.set(1,3,"Please enter password")
  if wrong then
    gpu.set(1,1,"UCIS Rocket Control Centre")
term.setCursor(1,2)
gpu.set(1,3,"Please enter password")
    wrong=false
  end
  term.setCursor(24,3)
  local input=io.read()
  if input==password then
     r.setOutput(side,15) -- check if this is the correct function
     os.sleep(delay)
     r.setOutput(side,0) -- same here
  else
     wrong=true
  end
end

Sincerly 

 

The Duke of Crawley

Link to post
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Hi The Duke of Crawley,

 

I was actually working on something very similar as well this weekend. I opted to use the term.read() function, which allows you to mask the input. I don't think io.read() does this.. Would be cool if you could link the documentation for that function.

 

Here's a snippet of my code. I'd be happy to share the whole program with you if you'd like.

answer = text.trim(term.read(nil, false, nil, "*"))  -- Masking input characters; trim newline

Note that the one downside to using term.read() is that it will also append a "\n" newline to your input which can cause the input not no match your configured password of course. I resolved this by using the text.trim() to remove it.

 

Hope this helps.

 

Cheers!

Link to post
Share on other sites
  • 0

(edit) "i said to early it worked you where right about the text.trim because he is not accepting my password, but now icant get the text.trim to work, i would love if you share the program"

 

(edit 2) "its working righ now

 

Thanks man after i tryed somethings with the piece of code you gave me its working now

and there is no extra newline. the only 2 things i now want know is how do i make sure nobody can shut the program off with ctrl+alt+c and how do i make sure its starts upon boot

 

for people who wants the somewhat renewed code for a password door 

thanks to kevinkk525 for providing the base code that i used

the new code is now:

local component=require("component")
local r=component.redstone
local gpu=component.gpu
local term=require("term")
local text-require("text")


---- config section
local password="ucisrrc876"
local delay=1 --time the door stays open
local side=5 --side of the door, test this
-----


local wrong=false


while true do
  term.clear()
  gpu.set(1,1,"UCIS Rocket Control Centre")
  term.setCursor(1,2)
  gpu.set(1,3,"Please enter password")
  if wrong then
    gpu.set(1,1,"UCIS Rocket Control Centre")
    term.setCursor(1,2)
    gpu.set(1,3,"Please enter password")
    wrong=false
  end
  term.setCursor(24,3)
  input = text.trim(term.read(nil, false, nil, "*"))
  if input==password then
     r.setOutput(side,15) -- check if this is the correct function
     os.sleep(delay)
     r.setOutput(side,0) -- same here
  else
     wrong=true
  end
end
Edited by thedukeofcrawley
Link to post
Share on other sites
  • 0

To have any program run when the computer boots, you will need to call it from an autorun script.

  1. First, what I would suggest is to place your program in the "/usr/bin" directory, that way it can be called by name without specifying the directory path. This is optional but I find it useful.
  2. Next, create a new file in the root "/" directory, called "autorun.lua". In this script, use the following code, supposing your program name was "pass.lua". Then reboot it too test. 
os.execute("pass.lua")

As far as preventing program termination, I have found one post that describes a method involving creating your answer string from key strokes; however I have not implemented it yet myself. If you do let me know how it worked out for you.

 

My program is below. I'd consider it 90% done with some potential enhancements. I'll release it in a more formal manor when I'm fully done, but you're welcome to use whatever you'd like.

 

Cheers!

 

--[[ 
  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 = "password"
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, 0)
  os.sleep(duration)
  rs.setOutput(s, 255)
end

--[[ Main ]]-------------------------------------------------------------------

-- Close door on init
rs.setOutput(s, 255)

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 == "admin" 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

 

Link to post
Share on other sites
  • 0

thanks for the help,

 

i cant get much out from the program terminiation you had send, but its starts up from boot right now i will send the new code with this message

i hope sombody else can help me with the prevent termination

local component=require("component")
local r=component.redstone
local gpu=component.gpu
local term=require("term")
local text=require("text")
local computer=require("computer")
local os=require("os")


---- config section
local password="ucisrrc876"
local delay=1 --time the door stays open
local side=5 --side of the door, test this
-----


local wrong=false


while true do
  term.clear()
  gpu.set(1,1,"UCIS Rocket Control Centre")
  term.setCursor(1,2)
  gpu.set(1,3,"Please enter password")
  if wrong then
    gpu.set(1,1,"UCIS Rocket Control Centre")
term.setCursor(1,2)
gpu.set(1,3,"Please enter password")
    wrong=false
  end
  term.setCursor(24,3)
  input = text.trim(term.read(nil, false, nil, "*"))
  if input==password then
     r.setOutput(side,15) -- check if this is the correct function
     os.sleep(delay)
     r.setOutput(side,0) -- same here
  else
     term.clear()
gpu.set(1,1, "UCIS Rocket Control Centre")
gpu.set(1,3, "Acces Denied")
os.sleep(delay)
computer.shutdown(true)
  end
end
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.