Jump to content




How To Improve My Lock?

computer

  • You cannot reply to this topic
5 replies to this topic

#1 YuvonDovah

  • Members
  • 28 posts

Posted 13 September 2013 - 03: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")


#2 electrodude512

  • Members
  • 167 posts
  • LocationEastern USA

Posted 13 September 2013 - 03: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?).

#3 Cranium

    Ninja Scripter

  • Moderators
  • 4,031 posts
  • LocationLincoln, Nebraska

Posted 13 September 2013 - 03: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()


#4 YuvonDovah

  • Members
  • 28 posts

Posted 14 September 2013 - 02:51 AM

Thank you both very much!

#5 Zudo

  • Members
  • 800 posts
  • LocationUK

Posted 14 September 2013 - 12:04 PM

View PostCranium, on 13 September 2013 - 03:45 PM, said:

print("Unable to authenticate!/nPlease contact a system administrator!")

This would not be visible, unless you had a ridiculously laggy PC.

#6 YuvonDovah

  • Members
  • 28 posts

Posted 14 September 2013 - 12:10 PM

View PostZudoHackz, on 14 September 2013 - 12:04 PM, said:

View PostCranium, on 13 September 2013 - 03:45 PM, said:

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.





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users