what I would suggest is creating a table for all users, all of my computers have a main table in which EVERYTHING is stored (rather than using variables I assign a table value) so that I can export everything to one string. so:
if type(record)~="table" then record={} end
local function prompt(q,y,n) --a function we will be using to get a yes or no answer for anything, very usefull
while true do
term.clear()
term.setCursorPos(1,1)
print(q.." ["..y.." | "..n.."]")
local prompt=read()
if prompt==y then
return y
elseif prompt==n then
return n
end
end
end
local function load(file) --a function to load the usernames from the file we saved last session
if fs.exists(file) then
record["users"]=textutils.unserialize(io.open(file):read) -- I will explain this later
else
print("user file not found")
record["users"]={}
end
end
local function createuser(user, file) --add users to the list and save them to the file
if user==nil then
print("Enter new username")
local user=read()
end
term.clear()
term.setCursorPos(1,1)
print("enter password for "..user)
local pass=read("*")
record["users"][user]={}
record["users"][user]["password"]=pass
io.open(file,"w+"):write(textutils.serialize(record["users"]))
print("Username created")
end
local function login() --the actual login function
term.clear()
term.setCursorPos(1,1)
print("Enter your username")
record["username"]=read()
if record["users"][record["username"]]~=nil then
term.clear()
term.setCursorPos(1,1)
print("Enter password for "..record["username"])
local password=read("*")
if record["users"][record["username"]]["password"]==password then
print("LOGGED IN")
return true
else
print("Incorrect password, restarting")
sleep(2)
reboot()
end
else --if record["users"][record["username"]] is nil (not already in the database)
local answer=prompt("username: "..record["username"].." not found, would you like to add it?","y","n")
if answer=="y" then
createuser(record["username"], "userfile")
sleep(2)
reboot()
elseif answer=="n" then
reboot()
end
end
end
then you call the functions:
load("userfile")
if login()~=true then
print("login process failed, restarting")
sleep(2)
reboot()
else
print("Welcome "..record["username"])
end
THIS IS NOT TESTED
with such a long program I have probably made a mistake somewhere but you get the general idea, what I am trying to say is that using tables to store data and then serializing them and storing them is the best way to store data
lol, thinking back I am not entirely sure why I just wrote an entire program when you were just asking for help… :ph34r:/>/>