Posted 23 April 2013 - 03:28 PM
Here, as my first tutorial, I'll be showing how to use the File System API for creating accounts and logging in.
Creating the account creation file
If you want to have accounts, it would mostly be easier to use a program to help you out with it.
You can start with having printing lines to show account creation process.
After the password line, you'll of course want to put the same "read" function from the username, except using "password = read()". No further explanation for this small bit is needed.
Once you have that down, the last thing you'll want is a code to imprint the password, close the file, and end the program. Done like so:
"account.close" stops the file from being used so that the password is saved.
There, the file is done. Here's what the code should look like in the end:
That's it! It's basic, and I didn't have the time to write all of it as I had to go to bed, but I'll add the next part in later, I promise!
Creating the account creation file
If you want to have accounts, it would mostly be easier to use a program to help you out with it.
You can start with having printing lines to show account creation process.
print("Account name:")
---In-between code to focus on
print("Password:")
Now, to create the account, I'm not doing things so advanced they aren't needed, so we'll implement code to make directories for the prime administration. This is before the "print("Account name:")" code.
fs.makeDir("dir1")
fs.makeDir("dir2")
fs.makeDir("dir3")
There we have it! Now, to read the username you want using "io.read" method:
username = read()
After that, you'll want to combine the directories and the username file, then open it for writing. Make sure there is a variable to represent the outcome of "fs.open" and "fs.combine":
a = fs.combine("dir1/dir2/dir3", username)
account = fs.open(a, "w")
Now that we have that done, let's move on to reading the password.After the password line, you'll of course want to put the same "read" function from the username, except using "password = read()". No further explanation for this small bit is needed.
Once you have that down, the last thing you'll want is a code to imprint the password, close the file, and end the program. Done like so:
account.write(password)
account.close()
"account.write" enters the password so that it can be read by any program interacting with it."account.close" stops the file from being used so that the password is saved.
There, the file is done. Here's what the code should look like in the end:
fs.makeDir("dir1")
fs.makeDir("dir2")
fs.makeDir("dir3")
print("Account name:")
username = read()
a = fs.combine("dir1/dir2/dir3", username)
account = fs.open(a, "w")
print("Password:")
password = read()
account.write(password)
account.close()
eof = true
There, now we have a program that simplifies creation of accounts.That's it! It's basic, and I didn't have the time to write all of it as I had to go to bed, but I'll add the next part in later, I promise!