Posted 09 April 2015 - 07:47 AM
Hi again, I have another question regarding a simple register and login with tables. The thing is that I can't run through the tables using the loop For. I don't know what I'm doing bad. I searched in the web and in the forum but I can't find something that I can use.
Here is my code:
I'm pretty sure there is another way much simplier than this, but that is not my problem right now, I just want to finish this first. If you execute the code, It will prompt the first menu, login and register. Select register and it will ask user and pwd. When the pwd is entered, the program is terminated. :/
Thank you in advance
Here is my code:
local users = {}
local passwords = {}
local key, keymenu, uslog, pwdlog, us_aux, pwd_aux, i
print("1. Login")
print("2. Register")
keymenu = read()
if keymenu == 2 then
repeat
for i=1, #users do
term.clear()
write("User: ")
users[i] = read()
for i=1, #passwords do
term.clear()
write("Password: ")
passwords[i] = read("*")
end
end
print("Continue? Y/N")
key = read()
until key == N
else
term.clear()
term.setCursorPos(1,1)
write("User: ")
uslog = read()
write("Password: ")
pwdlog = read("*")
for i=1, #users do
for i=1, #passwords do
if uslog == users[i] or pwdlog == passowrds[i] then
us_aux = uslog
pwd_aux = pwdlog
end
end
end
if us_aux == uslog and pwd_aux == pwdlog then
term.clear()
term.setCursorPos(24,9)
print("Login successful")
end
end
I'm pretty sure there is another way much simplier than this, but that is not my problem right now, I just want to finish this first. If you execute the code, It will prompt the first menu, login and register. Select register and it will ask user and pwd. When the pwd is entered, the program is terminated. :/
Thank you in advance