Here's some nice username/password loading and saving functions.
function saveUserdata(filename, user, pass)
local file = fs.open(filename, 'w')
if file then
file.writeLine(user)
file.writeLine(pass)
file.close()
end
end
function loadUserdata(filename)
local file = fs.open(filename, 'r')
if file then
local user = file.readLine()
local pass = file.readLine()
return user, pass
end
end
And here are the functions in your script:
function saveUserdata(user, pass)
local file = fs.open('.users/'..user, 'w')
if file then
file.write(pass)
file.close()
end
end
function loadUserdata(user)
local file = fs.open('.users/'..user, 'r')
if file then
local pass = file.readAll()
file.close()
return pass
end
end
print("Welcome to spongy141's account program, for the follow ?s please reply with and only a yes or no.")
term.write("Hello welcome! Are you new here?")
if read() == ("yes") then
print("Well then you need to make an account!")
print("First your going to enter your username, then password")
local username = read()
local password = read("*")
print("Your account information:")
print(username)
print(password)
saveUserdata(username, password) -- saves the user's user and pass to a filename of the username
-- in the folder ".users"
-- so if someone registers with the username "Bob", it'll save to the file ".users/Bob"
else
print("Please fill in your account information")
term.write("Account username:?")
local username = read()
local password = loadUserdata(username)
if password then -- checks if the username exists (if the password exists, so does the user)
term.write("Now your password:")
if read("*") == password then
print("Welcome-")
write(username)
else
print("Incorrect Password")
os.reboot()
end
else
print("Username does not exist")
os.reboot()
end
end
Went ahead and indented it too, it really helps ^^