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

[PROGRAM] Adv door lock with custom and pass input (Beta)

Started by dan14941, 18 January 2013 - 07:36 PM
dan14941 #1
Posted 18 January 2013 - 08:36 PM
Passcode Lock (Beta 0.2)

Lock any door!

This is a very simple program that can make your doors have custom password input to avoid intruders it took me 20 minutes to code but its done
Code:
Spoiler
--Lock function
function Lock()
   write( "Please chose a passcode:")
   p = read("*")
   textutils.slowPrint("Are You Shure?")
   x = io.read()
   if x == "yes" then
		 Passcode()
   elseif x == "no" then
			 Lock()
   else
   Lock()
   end
end
--Passcode function
function Passcode()
  term.clear("middle")
  print("Ok then")
  write("Passcode:")
  y = read("*")
  if y == p then
		print("Correct!")
		print("Access Granted!")
		redstone.setOutput("bottom", true)
		sleep(3)
		redstone.setOutput("bottom", false)
		write("Do you want to change your passcode (y/n):")
		t = io.read()
		if t == "y" then
		Lock()
		elseif t == "n" then
		Passcode()
		else Passcode()
		end
  elseif y ~= p then
  print("Incorrect")
  print("Access Denied!")
  Passcode()
  end
end  
--run
Lock()
I give you full permission to copy and use on your servers or even in singleplayer, remember that the redstone output has to be underneath the computer!

Screenshots
SpoilerSelect Pass:

Confirmation:

Input:

Input Correct

Planned
Spoiler
  • New password feature
  • Owner name
  • password format to be written in stars ****
If you have code for one or more of these on pastebin please pm me the link!

P.s. If you use it on your server could i have the ip to test if it works?
EDIT:If you use can i please know so i know how many people use my code?
Skullblade #2
Posted 19 January 2013 - 12:48 AM
textutils.slowPrint("Are You Shure?")
you spelled "sure" wrong….
Engineer #3
Posted 19 January 2013 - 12:50 AM
Make it so that it asks where to output the redstone.

local output = ""
write("Where to output my redstone signal?")
reader = read()
if reader == "back" then
   output = "back"
elseif .. (all the outputs)
end

redstone.setOutput(output, true)
sleep(2)
redstone.setOutput(output, false)

Also make it anti-terminate able.

Otherwise I can hack into your computer and set the redstone output manually to open the door.

http://www.computerc..._Protected_Door

Use this link and scroll to the bottom how to anti terminate it :)/>
Skullblade #4
Posted 19 January 2013 - 01:01 AM
just tell him…

put this at the top of your code

os.pullEvent=os.pullEventRaw
Engineer #5
Posted 19 January 2013 - 02:08 AM
just tell him…

put this at the top of your code

os.pullEvent=os.pullEventRaw

Well, thats the permanent one. Under that one is code that you can re-enable terminate. And he can probabely figure this out on is own, I am just pointing it out
dan14941 #6
Posted 20 January 2013 - 02:04 AM
Thanx for your help new release soon!

textutils.slowPrint("Are You Shure?")
you spelled "sure" wrong….
oops
dan14941 #7
Posted 20 January 2013 - 12:19 PM
ok adding
local pullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
-- If the desired conditions are met, you can run this line to allow the program to be terminated.
os.pullEvent = pullEvent
to the code
superaxander #8
Posted 21 January 2013 - 09:30 AM
Tips:
-You can make the password look like stars by doing read("*") instead of read()
-You can reset the pointer so your ok then appears on top by doing term.setCursorPos(1,1)

EDIT: You already did the star thing already why is it on your todo list then?
Edited on 21 January 2013 - 08:31 AM
NeverCast #9
Posted 21 January 2013 - 10:49 AM
Yeah I found a way to crash this, if you enter a passcode apx 256 times, You'll overflow the LuaVM Stack, because you're calling passcode inside passcode, the fastest way to do this is to just press enter each time it asks for a password.

My suggestion, put passcode in a while loop instead of having it recursively calling itself.

Edit:

You should consider saving the passcode to file, and checking if the file exists when you start, if it does exist, call passcode not lock, so that I can't restart the computer and set my own passcode :)/>
dan14941 #10
Posted 21 January 2013 - 11:33 PM
Tips:
-You can make the password look like stars by doing read("*") instead of read()
-You can reset the pointer so your ok then appears on top by doing term.setCursorPos(1,1)

EDIT: You already did the star thing already why is it on your todo list then?
oops

Yeah I found a way to crash this, if you enter a passcode apx 256 times, You'll overflow the LuaVM Stack, because you're calling passcode inside passcode, the fastest way to do this is to just press enter each time it asks for a password.

My suggestion, put passcode in a while loop instead of having it recursively calling itself.

Edit:

You should consider saving the passcode to file, and checking if the file exists when you start, if it does exist, call passcode not lock, so that I can't restart the computer and set my own passcode :)/>
IM not good at while loops
Engineer #11
Posted 22 January 2013 - 04:02 AM
Tips:
-You can make the password look like stars by doing read("*") instead of read()
-You can reset the pointer so your ok then appears on top by doing term.setCursorPos(1,1)

EDIT: You already did the star thing already why is it on your todo list then?
oops

Yeah I found a way to crash this, if you enter a passcode apx 256 times, You'll overflow the LuaVM Stack, because you're calling passcode inside passcode, the fastest way to do this is to just press enter each time it asks for a password.

My suggestion, put passcode in a while loop instead of having it recursively calling itself.

Edit:

You should consider saving the passcode to file, and checking if the file exists when you start, if it does exist, call passcode not lock, so that I can't restart the computer and set my own passcode :)/>
IM not good at while loops

Sample code:

while true do
  term.clear()
  term.setCursorPos(1,1)
  print("password: ")
  reader = read("*")
  if reader == "test:p" then -- if this is not the case, it will redo the code, it keeps asking until you hit this
	  print("Acces granted!")
	  break -- breaks out of the loop
  end
end
SuicidalSTDz #12
Posted 22 January 2013 - 05:25 AM
Looks good so far, good luck with Lua!
dan14941 #13
Posted 27 January 2013 - 01:17 PM
Looks good so far, good luck with Lua!
im good at lua
Mailmanq! #14
Posted 27 January 2013 - 01:57 PM
This is probably intended to be a startup program, so make it save the password to a file by doing

if not fs.exists(".password") then
  print("What would you like the password to be?")
  local p = io.read()
  local passwordFile = fs.open(".password", w)
  passwordFile.write(p)
else
   local p = fs.open(".password", r")
   local p = p[1]
end
SuicidalSTDz #15
Posted 28 January 2013 - 09:44 AM
Looks good so far, good luck with Lua!
im good at lua
I never said you weren't good with Lua. I am simply saying GOOD LUCK with any further projects/programs. ;)/>
SuicidalSTDz #16
Posted 28 January 2013 - 09:51 AM
This is probably intended to be a startup program, so make it save the password to a file by doing

if not fs.exists(".password") then
  print("What would you like the password to be?")
  local p = io.read()
  local passwordFile = fs.open(".password", w)
  passwordFile.write(p)
else
   local p = fs.open(".password", r")
   local p = p[1]
end
That would not work since Write and Read must be in string form like so:
"w" or "r"
Unless you made a variable like so(which would be stupid):
local r = "r"
local w = "w"
But without that being said, you had the right idea. ;)/>

EDIT: You must also close the file like so:
local p = io.read()
local passFile = fs.open("password", "r")
passFile.write(p)
passFile:close()