26 posts
Posted 13 September 2013 - 04:02 PM
Is there a way to improve this lock code? Also how would I add a counter, so say you get it wrong 3 times it shuts down for a hour? And is there a way to stop people hacking it via a disk drive?
Lock
os.pullEvent = os.pullEventRaw
local done = false
while done == false do
term.clear()
term.setCursorPos(1,1)
write("Password:")
local password = read('*')
term.clear()
term.setCursorPos(1,1)
if password == "PASSWORD" then
done = true
elseif password == "PASSWORD" then
print("Access Granted")
redstone.setOutput("right",true)
sleep(5)
redstone.setOutput("right",false)
sleep(2)
redstone.setOutput("back",true)
sleep(1)
redstone.setOutput("back",false)
else
print("Access Denied")
sleep(2)
term.clear()
term.setCursorPos(1,1)
end
end
Startup
os.run({}, "lock")
171 posts
Location
Eastern USA
Posted 13 September 2013 - 04:30 PM
To add a counter, just put a variable that gets incremented in the else that gets run when the password's wrong. If the counter limit's exceeded then reset the counter to 0 and lock up.
To lock the computer for an hour and prevent people from just restarting the computer, read the current time with os.time(), write the time the computer should unlock to a file, then wait. If the computer is restarted, it'll read this file, see that the time hasn't expired, and continue waiting. I'm not completely sure this'll work - it might not across a server restart.
The only way I can think of to stop people from using a disk drive is by modifying rom/shell to not boot off of disk drives , which would be cheating if you're only making a door lock and not an OS or something. Another way is by putting the computer next to a wireless modem and encasing it in bedrock (cheating again…) or reinforced iridium tungstensteel blocks if you have gregtech. The user types the password into another computer, which sends the password (hopefully encrypted in some way) (try challenge-response) to the computer in the bedrock, which, if the password is right, sends a redstone signal through the bedrock to the door (bedrock conducts through repeaters, right?).
3790 posts
Location
Lincoln, Nebraska
Posted 13 September 2013 - 04:45 PM
os.pullEvent = os.pullEventRaw
local auth = false
for i = 1,3 do
term.clear()
term.setCursorPos(1,1)
write("Password:")
local password = read('*')
term.clear()
term.setCursorPos(1,1)
if password == "PASSWORD" then
print("Access Granted")
redstone.setOutput("right",true)
sleep(5)
redstone.setOutput("right",false)
sleep(2)
redstone.setOutput("back",true)
sleep(1)
redstone.setOutput("back",false)
auth = true
break
end
if not auth then
print("Authentication failed!/nTries remaining: "..3 - i)
end
end
if not auth then
print("Unable to authenticate!/nPlease contact a system administrator!")
local file = fs.open("startup", "w")
file.write("print('Authentication failed, system lockdown! Please insert authentication disk and reboot!') os.pullEvent() os.shutdown()")
file.close()
os.shutdown()
end
and you would need a authentication disk that has this written as the startup file in it:
local file = fs.open("startup", "w")
file.write("shell.run('lock')")
file.close()
26 posts
Posted 14 September 2013 - 03:51 AM
Thank you both very much!
1114 posts
Location
UK
Posted 14 September 2013 - 01:04 PM
print("Unable to authenticate!/nPlease contact a system administrator!")
This would not be visible, unless you had a ridiculously laggy PC.
26 posts
Posted 14 September 2013 - 01:10 PM
print("Unable to authenticate!/nPlease contact a system administrator!")
This would not be visible, unless you had a ridiculously laggy PC.
I realized that after I tried it which is a shame, is there a way to fix that? Also when I tried the authentication disk it didn't unlock the computer.