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

Password Protected Door

Started by Witnessedhades, 01 October 2012 - 02:00 AM
Witnessedhades #1
Posted 01 October 2012 - 04:00 AM
I have made a small program that lets you password protect a door the code is simple its just

local password = "Put Your PassWord Here"

while true do
print("Password required to enter")
print("Please enter password below")
local passwordRead = read("*")
if passwordRead == password then
print("Access Granted")
rs.setOutput("right", true)
sleep(5)
rs.setOutput("right", false)
os.shutdown()
else
print("Access Denied")
sleep(2)
os.shutdown()
end
end
put your password in the top
stilldabomb #2
Posted 01 October 2012 - 04:21 AM
Eh, it's done on a daily basis, but you had the courage to post it on CCForums! I'll give you credit for that XD
jag #3
Posted 01 October 2012 - 07:54 AM
You got it in a while loop, but still you shutdown the computer if you do the wrong password.
It would be more efficient to do os.reboot() instead of os.shutdown().
ChaddJackson12 #4
Posted 02 October 2012 - 02:56 AM
Why the while loop?
ChaddJackson12 #5
Posted 02 October 2012 - 02:57 AM
Eh, it's done on a daily basis, but you had the courage to post it on CCForums! I'll give you credit for that XD

In the summer before I couldn't connect to the forums for a month. There was only 2 pages of programs and one password door lock. XD
jag #6
Posted 02 October 2012 - 09:38 AM
Look, if you removed the os.shutdown() and add some term.clear() it would be "better".
You could also remove the variable "passwordRead", to get a smaller code.
local password = "Put Your PassWord Here"

while true do
  term.clear()  -- clears the screen, simple.
  term.setCursorPos(1,1) -- sets the point where to print.

  print("Password required to enter")
  print("Please enter password below")
  if read("*") == password then
	print("Access Granted")
	rs.setOutput("right", true)
	sleep(5)
	rs.setOutput("right", false)
  else
	print("Access Denied")
	sleep(2)
  end
end
This will print out like this:
Password required to enter
Please enter password below
And still work the same like this
Password required to enter
Please enter password below
**********************
And the like this
Password required to enter
Please enter password below
**********************
Access Granted
The door opens, 5 seconds later the script restars.
Mr. Fang #7
Posted 04 October 2012 - 01:09 AM
if you have os.reboot() then you'll be able to keep the computer open and try again.
But with os.shutdown() you have to exit the computer GUI and open it again to do anything.
jag #8
Posted 04 October 2012 - 05:41 AM
if you have os.reboot() then you'll be able to keep the computer open and try again.
But with os.shutdown() you have to exit the computer GUI and open it again to do anything.
If you do it like I did, (with while loops) you wont even need to shutdown/reboot!