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

password and alarm protected door

Started by jakemcginnz, 03 August 2012 - 03:08 PM
jakemcginnz #1
Posted 03 August 2012 - 05:08 PM
for this you will need tekkit. first put a computer next to your door. then place an alarm on back by shift clicking. most credit goes to unstopablekk .
you can change the text however you want. also the direction of the redstone output. now type "edit startup" into the computer and start copying this code into it.

local oldPull = os.pullEvent;
os.pullEvent = os.pullEventRaw;
term.clear()
term.setCursorPos(1,1)
correctpass = "Open"
write("Enter Password: ")
pass = read("*")
if pass == (correctpass) then
write("Opening Door")
redstone.setOutput("back", true )
sleep(3)
redstone.setOutput("back", false )
os.shutdown()
end
write("Incorrect Password")
sleep(3)
term.clear()
term.setCursorPos(1,1)
textutils.slowPrint("Intruder Alert Activating Alarm!")
sleep(1)
redstone.setOutput("back",true )
sleep(3)
redstone.setOutput("back",false )
os.shutdown()
os.pullEvent = oldPull;

now your done. press ctrl then s. then ctrl then e. now type reboot into the computer
Gavjenks #2
Posted 11 August 2012 - 08:06 AM
couldnt somebody just boot from disk with a program that sets all directional redstone true (wait) then false? I feel like passwords have to be by modem to be secure, so the actual signal that opens the door can be inside a force field or hidden somewhere else.
Tiin57 #3
Posted 11 August 2012 - 04:06 PM
I have improved (see: completely rewritten) this code to work better and include the server/client authentication that I so love, as Gavjenks suggested. This is the client code:

os.pullEvent = os.pullEventRaw
rednet.open("back")
rednet.open("right")
rednet.open("top")
rednet.open("bottom")
rednet.open("front")
rednet.open("left")
rs.setOutput("right", false) -- Change "right" to whatever side the door is on.
print("Welcome to TiinTech Security System.") -- DO NOT MODIFY THIS. THIS IS THE EQUIVALENT OF A COPYRIGHT.
print("Please enter the password.")
local f = read("*")
rednet.broadcast(f)
local scrap, m = rednet.receive()
if m == "use1good" then
print("Access Granted.") -- Customize this message as you wish.
local l = "right" -- Change "right" to whatever side the door is on.
rs.setOutput(l,true)
sleep(3)
rs.setOutput(l,false)
term.clear()
term.setCursorPos(1,1)
elseif m == "use2good" then
print("Welcome, User 2.") -- Customize this message as you wish.
local l = "right" -- Change "right" to whatever side the door is on.
rs.setOutput(l,true)
sleep(3)
rs.setOutput(l,false)
term.clear()
term.setCursorPos(1,1)
elseif m == "x" then
print("Password denied.")
print("Alarm activated.")
rs.setOutput("back", true) -- Change this to whatever side the alarm is on.
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
shell.run("reboot")
And here's the server code:


local passcheck = fs.exists(312)
if passcheck == false then
print("TiinLock Server Setup.")
print("Please enter the password desired. Then, save and reboot the computer.")
shell.run("rename","tiinlockserver","startup")
shell.run("edit","312")
print("Don't forget to set the client program as startup on all door computers!")
local red = rednet.open
red("left")
red("right")
red("top")
red("back")
red("bottom")
red("front")
print("Server receiving on all sides.")
local scrap, msg = rednet.receive()
local tiin = fs.open("312", "r")
local tiinr = tiin.readAll()
if msg == tiinr then
rednet.broadcast("tiingood")
os.reboot()
else
rednet.broadcast("x")
os.reboot()
end
ChasedMonkey #4
Posted 05 September 2012 - 08:39 PM
Don't quote me on this, but I don't think you can copywrite code unless its something entirely new that has never been done before. Unless you get a lawer and spend $3000 to incorperate.

On another note, your code is pretty good. You might want to make the client only send information to the computer with the ID of the server. Otherwise someone could have their own computer sending "tiingood" to all computers.
wgcfatalahot #5
Posted 19 September 2012 - 01:08 AM
I have improved (see: completely rewritten) this code to work better and include the server/client authentication that I so love, as Gavjenks suggested. This is the client code:

os.pullEvent = os.pullEventRaw
rednet.open("back")
rednet.open("right")
rednet.open("top")
rednet.open("bottom")
rednet.open("front")
rednet.open("left")
rs.setOutput("right", false) -- Change "right" to whatever side the door is on.
print("Welcome to TiinTech Security System.") -- DO NOT MODIFY THIS. THIS IS THE EQUIVALENT OF A COPYRIGHT.
print("Please enter the password.")
local f = read("*")
rednet.broadcast(f)
local scrap, m = rednet.receive()
if m == "use1good" then
print("Access Granted.") -- Customize this message as you wish.
local l = "right" -- Change "right" to whatever side the door is on.
rs.setOutput(l,true)
sleep(3)
rs.setOutput(l,false)
term.clear()
term.setCursorPos(1,1)
elseif m == "use2good" then
print("Welcome, User 2.") -- Customize this message as you wish.
local l = "right" -- Change "right" to whatever side the door is on.
rs.setOutput(l,true)
sleep(3)
rs.setOutput(l,false)
term.clear()
term.setCursorPos(1,1)
elseif m == "x" then
print("Password denied.")
print("Alarm activated.")
rs.setOutput("back", true) -- Change this to whatever side the alarm is on.
sleep(1)
term.clear()
term.setCursorPos(1,1)
end
shell.run("reboot")
And here's the server code:


local passcheck = fs.exists(312)
if passcheck == false then
print("TiinLock Server Setup.")
print("Please enter the password desired. Then, save and reboot the computer.")
shell.run("rename","tiinlockserver","startup")
shell.run("edit","312")
print("Don't forget to set the client program as startup on all door computers!")
local red = rednet.open
red("left")
red("right")
red("top")
red("back")
red("bottom")
red("front")
print("Server receiving on all sides.")
local scrap, msg = rednet.receive()
local tiin = fs.open("312", "r")
local tiinr = tiin.readAll()
if msg == tiinr then
rednet.broadcast("tiingood")
os.reboot()
else
rednet.broadcast("x")
os.reboot()
end

So, when entering these codes into the computer, do I just type in the client and then the server code?
Mr. Fang #6
Posted 19 September 2012 - 01:41 AM
couldnt somebody just boot from disk with a program that sets all directional redstone true (wait) then false? I feel like passwords have to be by modem to be secure, so the actual signal that opens the door can be inside a force field or hidden somewhere else.
At any point you could just knock the door down lol
Mr. Fang #7
Posted 19 September 2012 - 01:43 AM
Just remember to hold the "Sneak" key while placing the alarm on the back of the computer. Otherwise the alarm part of this would be useless!
ChasedMonkey #8
Posted 25 September 2012 - 03:24 PM
If you just make a flopy disk and put a blank file on it called "startup" the computer will boot to the main window and you can just type "redset (door side) true". Even if the password itself was on a modem the door would open. But breaking the door down is the best option.
gamemaker152 #9
Posted 23 October 2012 - 12:09 AM
couldnt somebody just boot from disk with a program that sets all directional redstone true (wait) then false? I feel like passwords have to be by modem to be secure, so the actual signal that opens the door can be inside a force field or hidden somewhere else.
At any point you could just knock the door down lol
You could, but you could also make this code disarm a forcefield instead of a door. Which couldn't be broken
Orwell #10
Posted 23 October 2012 - 03:04 AM
If you just make a flopy disk and put a blank file on it called "startup" the computer will boot to the main window and you can just type "redset (door side) true". Even if the password itself was on a modem the door would open. But breaking the door down is the best option.

The computer that verifies the password (thus, the server) would also be the one opening the door…

What I used to do was to have the server inside a forcefield and the client on the outside. The client then sends the inputted password to the server. If it's correct, the server activates a tube projector to make a hole in the forcefield. This way you can't break down a door or something. : ) Worst thing that could happen is the client to get stolen (if you don't have lwc or lockette) or a keylogger getting installed on the client.
MathManiac #11
Posted 13 November 2012 - 01:47 PM
Absolutely Spiffing!
Tiin57 #12
Posted 13 November 2012 - 02:50 PM
I ought to slap myself.
There, I just did.
That second post? The one I made?
It's absolute junk. I am sorry for offending the gods.
xxxredportalxxx #13
Posted 16 January 2013 - 07:35 PM
Simple stuff, though i gues it does what you want it to :)/>
jjamess10 #14
Posted 20 January 2013 - 11:08 PM
I made my own code that stops floppy disks that make it run startup

Written in startup

password = '-Enter your door password-'
side = '-Where your door is-'
os. pullEvent = os.pullEventRaw	 ------ Stops Ctrl+T
term.clear()				   ------ Clears text on screen
print('Enter password')		  -----You can change Enter password to whatever you like
guess = read('*')		  -------Makes what you type on the computer * so people can read what you are typing
if password == guess then
  textutils.slowPrint('Password accepted -alarm disabled')
  rs.setOutput(side, true)
  rs.setOutput('-which side your alarm is-', false)
  sleep(5)				  -----Change 5 to how long you want the door to stay open
  rs.setOutput(side, false)
  os.reboot()				------So you can use the floppy disk hack if you get it right and you want to change the code after
end
textutils.slowPrint('Password incorrect')
sleep(0.5)
textutils.slowPrint('Activating alarm')
rs.setOutput('-which side your alarm is-', true)
sleep(3)
term.clear()
shell.run('startup')		----IMPORTANT---- This isn't os.reboot() so you can't use floppy disks with startup on them
theoriginalbit #15
Posted 21 January 2013 - 02:14 AM
I made my own code that stops floppy disks that make it run startup

Written in startup

password = '-Enter your door password-'
side = '-Where your door is-'
os. pullEvent = os.pullEventRaw	 ------ Stops Ctrl+T
term.clear()				   ------ Clears text on screen
print('Enter password')		  -----You can change Enter password to whatever you like
guess = read('*')		  -------Makes what you type on the computer * so people can read what you are typing
if password == guess then
  textutils.slowPrint('Password accepted -alarm disabled')
  rs.setOutput(side, true)
  rs.setOutput('-which side your alarm is-', false)
  sleep(5)				  -----Change 5 to how long you want the door to stay open
  rs.setOutput(side, false)
  os.reboot()				------So you can use the floppy disk hack if you get it right and you want to change the code after
end
textutils.slowPrint('Password incorrect')
sleep(0.5)
textutils.slowPrint('Activating alarm')
rs.setOutput('-which side your alarm is-', true)
sleep(3)
term.clear()
shell.run('startup')		----IMPORTANT---- This isn't os.reboot() so you can't use floppy disks with startup on them
Good job… however I will make these suggestions as a learning experience… They can use CTRL+R or CTRL+S to shutdown and reboot the computer and add their floppy disk startup in that way… Also can I make a very Important coding suggestion too… with your "shell.run('startup')", try to avoid calling a function or a program again to get an "infinite loop" as the stack that holds all this information will fill and you will get a stack overflow error… use a while loop instead

while true do
  -- code to repeat
end
jjamess10 #16
Posted 21 January 2013 - 02:34 AM
I made my own code that stops floppy disks that make it run startup

Written in startup

password = '-Enter your door password-'
side = '-Where your door is-'
os. pullEvent = os.pullEventRaw	 ------ Stops Ctrl+T
term.clear()				   ------ Clears text on screen
print('Enter password')		  -----You can change Enter password to whatever you like
guess = read('*')		  -------Makes what you type on the computer * so people can read what you are typing
if password == guess then
  textutils.slowPrint('Password accepted -alarm disabled')
  rs.setOutput(side, true)
  rs.setOutput('-which side your alarm is-', false)
  sleep(5)				  -----Change 5 to how long you want the door to stay open
  rs.setOutput(side, false)
  os.reboot()				------So you can use the floppy disk hack if you get it right and you want to change the code after
end
textutils.slowPrint('Password incorrect')
sleep(0.5)
textutils.slowPrint('Activating alarm')
rs.setOutput('-which side your alarm is-', true)
sleep(3)
term.clear()
shell.run('startup')		----IMPORTANT---- This isn't os.reboot() so you can't use floppy disks with startup on them
Good job… however I will make these suggestions as a learning experience… They can use CTRL+R or CTRL+S to shutdown and reboot the computer and add their floppy disk startup in that way… Also can I make a very Important coding suggestion too… with your "shell.run('startup')", try to avoid calling a function or a program again to get an "infinite loop" as the stack that holds all this information will fill and you will get a stack overflow error… use a while loop instead

while true do
  -- code to repeat
end
I have tested to see if Ctrl+s and Ctrl+r work and they do not because the code is in startup and it just puts them into the password screen and thanks for the loop code idea! I'll try that now.
theoriginalbit #17
Posted 21 January 2013 - 02:42 AM
I have tested to see if Ctrl+s and Ctrl+r work and they do not because the code is in startup and it just puts them into the password screen and thanks for the loop code idea! I'll try that now.
Try putting down a disk drive with a disk that has a startup, something simple like print("hi"), and then reboot the computer with ctrl+r
jjamess10 #18
Posted 21 January 2013 - 02:54 AM
Thanks for the help! I've used the loop code and it works perfectly!
jjamess10 #19
Posted 21 January 2013 - 02:58 AM
Do you have any idea of how to stop Ctrl+R and Ctrl+S?
Dlcruz129 #20
Posted 21 January 2013 - 05:27 AM
Do you have any idea of how to stop Ctrl+R and Ctrl+S?

Impossible. Ctrl-S and Ctrl-R are hard-wired into the Java code, and therefore may not be disabled.
jjamess10 #21
Posted 21 January 2013 - 04:32 PM
Impossible. Ctrl-S and Ctrl-R are hard-wired into the Java code, and therefore may not be disabled.

So Ctrl+T isn't hard-wired into the Java code?
theoriginalbit #22
Posted 21 January 2013 - 04:37 PM
Impossible. Ctrl-S and Ctrl-R are hard-wired into the Java code, and therefore may not be disabled.

So Ctrl+T isn't hard-wired into the Java code?
No because when CTRL+T is pressed it sends an event "terminate" to your code which terminates when it yields (unless you prevent it)… CRTL+S and CTRL+R go directly to the mod so and the code doesn't yield… or something along those lines…
jjamess10 #23
Posted 21 January 2013 - 04:48 PM
No because when CTRL+T is pressed it sends an event "terminate" to your code which terminates when it yields (unless you prevent it)… CRTL+S and CTRL+R go directly to the mod so and the code doesn't yield… or something along those lines…
Thanks, I understand.
Ctrl+T uses the computer and Crtl+S and Ctrl+R are programs in the mod itself
MudkipTheEpic #24
Posted 22 January 2013 - 04:22 AM
Well there is a way to stop control+r and s, but it is considered malicious and bricks ALL computers until that one is broken… Not gonna post it. Probably an LuaJ bug…

Edit: Bricks all CPUs for like 10 secs
Edited on 22 January 2013 - 03:54 AM