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

Username & Password Lock system, can you make one?

Started by Xolbor, 17 June 2013 - 02:13 PM
Xolbor #1
Posted 17 June 2013 - 04:13 PM
I want to know if you are able to enter a username AND a password in the same program to unlock a computer. I've tried everything I know what to do. Help?
Lyqyd #2
Posted 17 June 2013 - 10:49 PM
Split into new topic.

This is one of the most commonly created types of programs, so of course it can be done. Please post the code you have so far and we can help you fix it.
Anavrins #3
Posted 17 June 2013 - 11:44 PM
Maybe try something like this


local valid
local accounts = {
   ["username"] = "password",
   ["foo"] = "bar",
   ["xolbor"] = "roblox",
   ["anavrin"] = "nirvana"
}

term.clear()
term.setCursorPos(1, 1)

print("Enter username")
write("> ")
local input_user = read()

print("Enter password")
write("> ")
local input_pass = read("*")

for valid_user, valid_pass in pairs(accounts) do
   if (input_user == valid_user and input_pass == valid_pass) then valid = true end
end

if valid then print("Access Granted") else print("Access Denied") end
theoriginalbit #4
Posted 18 June 2013 - 12:11 AM
-snip-
With the way you have set up that table you can do this

if accounts[input_user] == input_pass then
  print("correct")
else
  print("incorrect")
end

EDIT: also with the way you have that loop you're best to exit the loop after a valid one has been found, no use continuing to search! Use `break` to exit a loop.