37 posts
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 Spoiler
Select 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?
497 posts
Location
The Big Apple, NY
Posted 19 January 2013 - 12:48 AM
textutils.slowPrint("Are You Shure?")
you spelled "sure" wrong….
1522 posts
Location
The Netherlands
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_DoorUse this link and scroll to the bottom how to anti terminate it :)/>
497 posts
Location
The Big Apple, NY
Posted 19 January 2013 - 01:01 AM
just tell him…
put this at the top of your code
os.pullEvent=os.pullEventRaw
1522 posts
Location
The Netherlands
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
37 posts
Posted 20 January 2013 - 02:04 AM
Thanx for your help new release soon!
textutils.slowPrint("Are You Shure?")
you spelled "sure" wrong….
oops
37 posts
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
620 posts
Location
Holland
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
392 posts
Location
Christchurch, New Zealand
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 :)/>
37 posts
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
1522 posts
Location
The Netherlands
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
1511 posts
Location
Pennsylvania
Posted 22 January 2013 - 05:25 AM
Looks good so far, good luck with Lua!
37 posts
Posted 27 January 2013 - 01:17 PM
Looks good so far, good luck with Lua!
im good at lua
131 posts
Location
I am omnipresent... DUH
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
1511 posts
Location
Pennsylvania
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. ;)/>
1511 posts
Location
Pennsylvania
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()