This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Chainmanner's profile picture

[IO] Account creation tutorial (for dummies!)

Started by Chainmanner, 23 April 2013 - 01:28 PM
Chainmanner #1
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.

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!
Dlcruz129 #2
Posted 23 April 2013 - 03:31 PM
This is more of a program than a tutorial. Tutorials usually explain how to use something or teach a concept.
PixelToast #3
Posted 23 April 2013 - 03:41 PM
i made one in vanilla lua, so excuse me if the syntax highlighting is screwed up: http://ptoast.tk/sl/luaaccounts
its still W.I.P.
i use it for a telnet server (still password protected :P/> so dont try snooping around my port 23)
also note, C:/lua/apis.lua contains infutil (saveprefs and readprefs), i plan on recreating fs aswell
my version is functional, though i was in the middle of coding it so it might error D:
Bubba #4
Posted 24 April 2013 - 01:29 PM
i plan on recreating fs aswell

What exactly do you mean by recreating fs? Fs is native in CC, and io is a wrapper. So are you going to add functionality to it?
NullSchritt #5
Posted 02 May 2013 - 11:17 PM
Still an interesting share, thanks.
CrazyTech13 #6
Posted 12 October 2013 - 01:01 PM
I agree with Dlcruz, I didn't understand the making of the directories and the combining of them, and I was also confused with the "w" in the fs.open(a, "w") please explain more :/
ElvishJerricco #7
Posted 17 October 2013 - 01:08 PM
It should be noted that storing the password in plain text like that is generally a bad idea. Most people hash the password and save that (salted hashing if possible, but I won't get into that here). Then to authenticate someone, you take the password that they type, hash that and see if the result is equivalent to the stored hash.

So why hash? Hashing algorithms are not easily reversible algorithms. There are no un-hash functions. So if someone gets access to the stored hash, they can't do anything with it. It's possible to have a "rainbow table" of text and the hashes they turn into. So if you have a large enough rainbow table, you can look up any hash. But for the better hash algorithms, such a table is impractical and would be terabytes in size. This is why complex passwords are harder to crack. Simpler ones are recorded in these rainbow tables first.

Point is, if someone somehow gets access to the files on the computer, you don't want them being able to read the passwords. You want them reading hashes.