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

Door lock with username and alarm

Started by candycool1234, 21 September 2012 - 12:03 AM
candycool1234 #1
Posted 21 September 2012 - 02:03 AM
I dont care what other people say i made this lock may not be first but i did not copy it.
I took what i new of coding and made this this is my first code so take it easy on me

os.pullEvent = os.pullEventRaw

print("Welcome Enter user")

correctuser = "Your user here"

write("Username:")

user = read("*")

if user == (correctuser) then
term.clear()

else
print("INCORRECT ACTIVATING ALARM")
rs.setOutput("back",true)
sleep(5)
os.shutdown()
end

correctpass = "Enter a password here"

write("Password:")

pass= read("*")

if pass == (correctpass) then
print("Welcome enter")
rs.setOutput("Side door is on",true)
sleep(3)
term.clear()
os.shutdown()

else
print("INCORRECT ACTIVATING ALARM")
rs.setOutput("back",true)
sleep(5)
os.shutdown()
end

if you have any problems let me know. :)/>/>
Mr. Fang #2
Posted 21 September 2012 - 03:16 AM
Great Door Lock, I'm sure it's been done before, but you did a wonderful job creating this!
Fatal_Exception #3
Posted 21 September 2012 - 07:49 AM
Simple, and gets the job done.
From a security standpoint, you should only give one error for invalid username OR password, rather than one for each.
Any information you indirectly give an attacker (which usernames are valid) makes it easier for them. With one error for both, they won't know if they got a valid username but the wrong password, so they have to try all combinations of usernames and passwords.
candycool1234 #4
Posted 05 August 2013 - 04:31 PM
Great idea and i created this on my own soo please be easy
Zudo #5
Posted 06 August 2013 - 03:29 AM
You might want to put this in [.code] tags and/or on pastebin.


os.pullEvent = os.pullEventRaw
local correctuser = "user" -- Always make your variables local, unless you need to change the core functions
local correctpass = "pass" -- Same here
local doorside = "side"
local alarmside = "side"
while true do
term.clear()
term.setCursorPos(1,1)
print("Welcome:")
write("Username: ")
local user = read()
write("Password:")
local pass = read("*")
if user == correctuser and pass == correctpass then
  print("Login correct. Please enter")
  rs.setOutput(doorside, true)
  sleep(3)
  rs.setOuput(doorside, false)
else
   print("Login incorrect!")
   rs.setOutput(alarmside, true)
   sleeep(5)
   rs.setOuput(alarmside, false)
  end
end

Improved :)/>