So I have a login program, which had the username and passwords in that program.
Now I have the usernames and passwords in a separate program from the login.
I have done what I think is right with the tables.
Here is the code for the login system:
Spoiler
--Login system
--username = {"admin", "account2", "account3"} --I've turned this off,
--password = {"pass", "account2", "account3"} --I've turned this off,
function load(users)
local file = fs.open(users,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
function load(users)
local file = fs.open(pass1,"r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
term.setCursorPos(18,4)
print("Login:")
term.setCursorPos(18,5)
print("------")
term.setCursorPos(18,6)
write("Username: ")
user = read()
term.setCursorPos(18,7)
write("Password: ")
pass = read("*")
for i=1, #user do
if user == users[i] and pass == pass1[i] then
access = true
end
end
if access == true then
print("Welcome, "..user.."!")
sleep(1)
term.clear()
term.setCursorPos(1,22)
print("Welcome, "..user.."!")
sleep(1)
term.clear()
term.setCursorPos(1,1)
shell.run("mainmenu")
else
print("Sorry! You entered the password or username incorrectly! Retry,")
sleep(2)
shell.run("login")
end
Here is the code for the 'users' program or file:
(Where I store the usernames and passwords.)
Spoiler
local users = {user1 = "admin", user2 = "2nd"}
local pass1 = {pass1 = "pass", pass2 = "2nd"}
Now when I run 'logon' (what I named the first code) I get this error:
logon:42: attempt to call index ? (a nil value)
Can anyone please help me? I am stuck on this. I've tried almost everything I think would fix it and Googling it doesn't help at all.