This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
hobnob11's profile picture

100% Secure Door Lock

Started by hobnob11, 27 February 2012 - 12:42 PM
hobnob11 #1
Posted 27 February 2012 - 01:42 PM
Making a door lock, one that cannot be terminated…

i have this:

pass = "password"
write "Password: "

read = ("*")
if input == pass then
print "Welcome!"
rs.setOutput("back" true)
rs.setOutput("right" true)
rs.setOutput("left" true)
sleep(3.5)
rs.setOutput("back" false)
rs.setOutput("right" false)
rs.setOutput("left" false)

else

print "Incorrect Password!"
sleep(2)
os.reboot()
end

and this (ref)


local password = "secret"
repeat
        write("Password: ")      -- write without line break
        local status, input = pcall( read )      -- read input
until input == password -- repeat until the input matches the password


im not a complete noob, but can someone combine these two so that the computer program cannot be terminated




P.S i have a program on a disk called startup that runs this, so that i can stop it from auto running if i need to
Espen #2
Posted 27 February 2012 - 02:56 PM
You cannot assign the read function name with a string. You have to call read() with a an optional parameter, e.g. read("*").
Also you used read() without assigning it to a variable. That means whatever you enter will not be usable.
But then you go and check if input == pass, but input hasn't been defined yet, so it will always be nil.
You need to assign input to read(), so that whatever someone enters is being fed into input.
Another thing is that you have to separate the parameters of the redstone functions with commas.

Regarding your question about termination prevention:

local pass = "password"

write "Password: "
local status, input = pcall( read, "*" )
if input == pass then
    print "Welcome!"
    rs.setOutput("back", true)
    rs.setOutput("right", true)
    rs.setOutput("left", true)
    sleep(3.5)
    rs.setOutput("back", false)
    rs.setOutput("right", false)
    rs.setOutput("left", false)
else
    print "Incorrect Password!"
    pcall( sleep, 2 )
    os.reboot()
end

If you're using pcall, then you can't just give it the function like you would call it normally.
You rather pass it the name of the function and all its parameters in a comma separated fashion.
So instead of this…
pcall( read("*") )
… it should be like this …
pcall( read, "*" )

I also pcall'd your second sleep function as that is another place where someone could try to terminate your program.
I didn't pcall the first one as that happens only if someone enters the correct password anyway.

Last but not least:
There is no 100% security! That is an impossibility. :D/>/>

Hope it helps, didn't test the code in-game yet though.
Cheers! B)/>/>
Kudendar #3
Posted 29 February 2012 - 04:08 AM
To make one that is the closest to "100% safe" you'll have to make it so the program cant be terminated, so that also means you'll have to completely finish the code first. Because once you make it so it cant be terminated you cant edit it anymore. To make it so it cant be terminated make a new file called startup and type:

while true do
shell.run("NameOfYourProgramHere")
end

Even this isn't 100% safe, I would make one that wont allow any disk drives to connect to it. Because you can shutdown the computer and then boot off of another startup file in a disk-drive. So if I had to worry about multiplayer then I would hope that server has a form of block protection and make sure no one could touch it.