I made one code with register and login but I cannot make it work
Thanks in advance
Pastebin your existing code.That. How to compare data (I.e. users) in a table with other data (i.e. passwords) in other table?
I made one code with register and login but I cannot make it work
Thanks in advance
local Usuarios = {}
while true do
term.clear() term.setCursorPos(1,1) -- clear screen and set cursor at the top
print("1. Login")
print("2. Register")
print("3. Change password")
print("4. Exit")
opc = io.read()
if opc == "1" then
term.clear() term.setCursorPos(1,1)
write("User: ")
user = io.read()
write("Password: ")
pass = read("*")
if Usuarios[user] and Usuarios[user].password == pass then -- check to see if the user exists and then compare the password with the given one
print("Access")
else
print("Denied")
end
sleep(1)
end
if opc == "2" then -- could put elseif here but because im using notepad++ i changed it to an if
term.clear() term.setCursorPos(1,1)
repeat
write("User: ")
user = io.read()
write("Password: ")
pass = read("*")
write("Rewrite password: ")
pass2 = read("*")
if pass ~= pass2 then
print("Passwords don't match")
end
Usuarios[user] = {} -- make a new user table called user e.g if user was 'ham' the table would be called ham
Usuarios[user].password = pass -- gives that user a password variable inside the table
print("Created")
sleep(1)
until pass == pass2
end
end
Usuarios[user] = {} -- make a new user table called user e.g if user was 'ham' the table would be called ham
Usuarios[user].password = pass -- gives that user a password variable inside the table
Usuarios[user] = pass
Usuarios[user] = {} -- make a new user table called user e.g if user was 'ham' the table would be called ham Usuarios[user].password = pass -- gives that user a password variable inside the table
Why make a whole new table, why not justUsuarios[user] = pass
Usuarios[user] = {} -- make a new user table called user e.g if user was 'ham' the table would be called ham Usuarios[user].password = pass -- gives that user a password variable inside the table
Why make a whole new table, why not justUsuarios[user] = pass
But that would replace the user for the password, right?
tab = {
["derp"] = 'derpspassword'
}
user = 'remiX'
pass = 'pass'
for username, password in pairs( tab ) do
print( username .. ' - ' .. password )
end
print()
tab[user] = pass
for username, password in pairs( tab ) do
print( username .. ' - ' .. password )
end
userdata={}
userdata["gopher"]={password="derp", accessLevel=5}
userdata["darkrising"]={password="herp", accessLevel=3}
for k,v in pairs(userdata) do
print(k..": pw="..v.derp..", access level="..v.accessLevel)
end
write("name>")
local name=read()
write("pw>")
local pw=read()
--//make sure name exists in the table before accessing members in the user's sub-table
--//otherwise you'll get attempt to index nil errors
if userdata[name] and userdata[name].password==pw then
print("valid login.")
else
print("Incorrect password!!")
to store more info about the user…userdata={} userdata["gopher"]={password="derp", accessLevel=5} userdata["darkrising"]={password="herp", accessLevel=3} for k,v in pairs(userdata) do print(k..": pw="..v.derp..", access level="..v.accessLevel) end write("name>") local name=read() write("pw>") local pw=read() --//make sure name exists in the table before accessing members in the user's sub-table --//otherwise you'll get attempt to index nil errors if userdata[name] and userdata[name].password==pw then print("valid login.") else print("Incorrect password!!")