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)
else
print("Please fill in your account information")
term.write("Account username:?")
if read() == username then
term.write("Now your password:")
if read("*") == password then
print("Welcome-")
write(username)
else
print("Incorrect")
os.reboot()
end
else
print("Incorrect")
os.reboot()
end
end
right now, all I need to do it allow the username and password to be saved in a other program, then used from that program again, please help.
help with my program
Started by Spongy141, Nov 27 2012 03:38 AM
2 replies to this topic
#1
Posted 27 November 2012 - 03:38 AM
#2
Posted 27 November 2012 - 03:56 AM
Here's some nice username/password loading and saving functions.
And here are the functions in your script:
Went ahead and indented it too, it really helps ^^
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 ^^
#3
Posted 27 November 2012 - 11:09 AM
Kingdaro, on 27 November 2012 - 03:56 AM, said:
Here's some nice username/password loading and saving functions.
And here are the functions in your script:
Went ahead and indented it too, it really helps ^^
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 ^^
2 user(s) are reading this topic
0 members, 2 guests, 0 anonymous users











