Posted 18 April 2013 - 11:28 PM
Hello everybody, this is my code:
Here is the problem: when I try to load the file, calling the function, I dont know how to compare that data with the one that the user inputs. In the register part, the function saves that table, is every ok. If I dont use the files and functions, the program works perfectly, but obviously if I reboot, all saved data in the tables will be lost.
Thanks in advance
Spoiler
local Users = {}
function save(Users,save)
local file = fs.open("save", "a")
file.write(textutils.serialize(Users))
file.close()
end
function load(save)
local file = fs.open("save", "r")
local data = file.readAll()
file.close()
return textutils.unserialize(data)
end
while true do
term.clear()
term.setCursorPos(1,1)
print("1. Login")
print("2. Register")
print("3. Exit")
opc = io.read()
if opc == "1" then
load(save)
term.clear()
term.setCursorPos(1,1)
write("User: ")
user = io.read()
write("Password: ")
pass = read("*")
if Users[user] and Users[user].password == pass then
print("Access")
print("Welcome back "..user)
sleep(1)
term.clear()
term.setCursorPos(1,1)
print("1. Change Password")
print("2. Exit")
opc = io.read()
if opc == "1" then
term.clear()
term.setCursorPos(1,1)
repeat
write("Password: ")
pass = read("*")
write("Rewrite Password: ")
pass2 = read("*")
if pass ~= pass2 then
print("Passwords don't match")
end
Users[user].password = pass
until pass == pass2
end
if opc == "2" then
term.clear()
term.setCursorPos(1,1)
print("Cerrando sesion...")
sleep(1)
end
else
print("Denied")
end
sleep(1)
end
if opc == "2" then
term.clear()
term.setCursorPos(1,1)
repeat
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
until pass == pass2
Users[user] = {}
Users[user].password = pass
save(Users,save)
print("Account Created")
sleep(1)
until pass == pass2
end
if opc == "3" then
os.reboot()
end
end
Here is the problem: when I try to load the file, calling the function, I dont know how to compare that data with the one that the user inputs. In the register part, the function saves that table, is every ok. If I dont use the files and functions, the program works perfectly, but obviously if I reboot, all saved data in the tables will be lost.
Thanks in advance