Posted 18 July 2012 - 12:05 AM
Right now, i'm trying to create a door lock script from scratch. Right now, it works very well, but is still vulnerable to inserting a disk and restarting it. I've got a bit of code that checks for disks and if they exist, erases and ejects them, but unfortunately the program only runs across that snippet of code when it's not nessicary (before the user enters the password)
What I would like to do is have the whole thing in a loop that runs 4 times per second, but .25 seconds it not nearly long enough for a user to enter a password.
How could I impliment a password system that loops while the user is still entering the password? I considered some kinda thing that checks if the user entered an input and if so, saving it into a variable and when the input is enter, combining the variables into one variable and checking it against the password, but is there a better way?
Here's my current code, for reference.
What I would like to do is have the whole thing in a loop that runs 4 times per second, but .25 seconds it not nearly long enough for a user to enter a password.
How could I impliment a password system that loops while the user is still entering the password? I considered some kinda thing that checks if the user entered an input and if so, saving it into a variable and when the input is enter, combining the variables into one variable and checking it against the password, but is there a better way?
Here's my current code, for reference.
Spoiler
oldPullEvent = os.pullEvent
os.pullEvent = os.pullEventRaw
while true do
if fs.exists("disk") then
k = fs.open("disk/startup", "No")
k.writeLine("write no")
k.close()
disk.eject("back")
disk.eject("bottom")
disk.eject("top")
disk.eject("front")
disk.eject("left")
disk.eject("right")
else
end
local side = "back"
local password = "limes"
local opentime = 5
term.clear()
term.setCursorPos(1,1)
write("Enter Password Now")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
rs.setOutput(side,true)
sleep(opentime)
rs.setOutput(side,false)
os.reboot()
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect!")
sleep(5)
os.reboot()
os.reboot()
end
end
os.pullEvent = oldPullEvent