Here is my current lock system. https://pastebin.com/sXnCsYyn
This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
How would I set up this
Started by Sluethen, 21 July 2017 - 02:13 AMPosted 21 July 2017 - 04:13 AM
So How would I make a login system that can read user's from a file? I'm new to this. I know how to make a login system but how would I Make it read and write to a file? I want it to read username's and password's from a file, but I'm not sure how.
Here is my current lock system. https://pastebin.com/sXnCsYyn
Here is my current lock system. https://pastebin.com/sXnCsYyn
Posted 21 July 2017 - 06:51 AM
Well, one way of doing it is saving a table full of usernames/passwords to a file, then importing the table into the program.
Look at textutils.seralize() and textutils.unserialize().
Another way is having a Users directory which has user files in it. So the name of the file is the username and the password would be saved in that file, raw or as a hash.
E.g.
Then you can make a for loop that looks for a file in that folder with the name entered by the user logging in on the computer. Fairly easy if you know how to read/write to a file and use a for loop. :)/>
Look at textutils.seralize() and textutils.unserialize().
Another way is having a Users directory which has user files in it. So the name of the file is the username and the password would be saved in that file, raw or as a hash.
E.g.
- Users (directory)
+ admin (content: password)
+ tommy (content: theawesomeguy123)
+ jack (content: jh1240d845)
Then you can make a for loop that looks for a file in that folder with the name entered by the user logging in on the computer. Fairly easy if you know how to read/write to a file and use a for loop. :)/>
Posted 22 July 2017 - 03:32 AM
I don't know how to read and write to a file(well) I know how to sorta write to a file but reading is nothing I've learned…. I should look into reading and writing files
I'm also having a bit of trouble understanding how I would make it read each user
I'm also having a bit of trouble understanding how I would make it read each user
Posted 22 July 2017 - 11:44 AM
For anything file-related, check out the FS API.
As for how to differentiate between users, you have a few options:
Option 1: Serialized Table - A table of users in the format tbl[ username ] = password. The table would be serialized and unserialized as necessary to write or read it from the file.
Option 2: Specialized file format - you could format your file in a particular way, eg. "username:password;username:password", then use string manipulation to extract the desired pairings. This would reduce file size compared to option 1, but is more difficult to implement.
Option 3: Multiple files - you could create a new file for each user (as suggested by Dave-ee Jones), where the file's name is the username and the contents is the password for that user.
Special Considerations: The majority of programs which store passwords in files make use of sha256, a hashing algorithm. This prevents someone from gaining access to the files on the computer and reading your password.
As for how to differentiate between users, you have a few options:
Option 1: Serialized Table - A table of users in the format tbl[ username ] = password. The table would be serialized and unserialized as necessary to write or read it from the file.
Option 2: Specialized file format - you could format your file in a particular way, eg. "username:password;username:password", then use string manipulation to extract the desired pairings. This would reduce file size compared to option 1, but is more difficult to implement.
Option 3: Multiple files - you could create a new file for each user (as suggested by Dave-ee Jones), where the file's name is the username and the contents is the password for that user.
Special Considerations: The majority of programs which store passwords in files make use of sha256, a hashing algorithm. This prevents someone from gaining access to the files on the computer and reading your password.
Posted 22 July 2017 - 05:01 PM
this is what i need to figure out to make my phone program more advance
Posted 22 July 2017 - 05:54 PM
I've went and gone with Dave-ee's way, but I'm having trouble with making it write on other lines. for a Admin status. I've done it before but I'm either missing something or I'm failing.
Posted 22 July 2017 - 09:52 PM
It might help XD
Posted 23 July 2017 - 01:47 AM
To write on a new line you just need to add a "\n" character to the end of the previous line.
For example,
For example,
"Hello\nWorld"
Would be written as:
Hello
World
Posted 23 July 2017 - 03:44 AM
Edit:Post has been eaten
Edited on 23 July 2017 - 02:35 AM
Posted 23 July 2017 - 03:48 AM
Sluethen, I would highly advise you to stop giving false advice. file.writeLine does not accept multiple parameters. Your example will write on multiple lines, but not necessarily the ones specified.
In addition, your comment on using "a" is extremely misleading. Append mode is very different from normal write mode!
In addition, your comment on using "a" is extremely misleading. Append mode is very different from normal write mode!
Edited on 23 July 2017 - 01:48 AM
Posted 23 July 2017 - 04:35 AM
I'm not quite sure why I posted that. .-. I ate it.
Edited on 23 July 2017 - 03:12 AM