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

help please

Started by Ristyo, 24 March 2013 - 04:47 PM
Ristyo #1
Posted 24 March 2013 - 05:47 PM
i am trying to make a program that can make people make a new account and login, but i am confused how to store the account information, can anybody help me?

Also im trying to make an installer to get pastebin files, what is the best possible way to do this?
Kingdaro #2
Posted 24 March 2013 - 06:24 PM
Saving account information:

-- example table of username and passwords
-- e.g. "Username = 'Password'"
accounts = {
  SomePerson = 'SomePassword';
  AnotherPerson = 'AnotherPassword';
}

-- make the table into a string
data = textutils.serialize(accounts)

-- save it to a file called "accounts"
file = fs.open('accounts', 'w') -- open "accounts" with writing mode
file.write(data)                -- write the stringed table
file.close()

Loading account information:

file = fs.open('accounts', 'r') -- open "accounts" for reading
content = file.readAll()        -- get what's in the file as a string to the variable "content"
file.close()

-- turn the file's text back into a table
accounts = textutils.unserialize(content)

print(accounts.SomePerson) --> SomePassword
Ristyo #3
Posted 24 March 2013 - 06:32 PM
the file.write(data)
the data is the accounts?
Kingdaro #4
Posted 24 March 2013 - 06:34 PM
Yes. It's the writeable version of the accounts table. You can't write a table directly to a file, so I used textutils.serialize() to turn it into a string.
Ristyo #5
Posted 24 March 2013 - 06:43 PM
thanks, the only reason im asking this cause im making an OS (well, everybody did) so thanks Kingdaro! ill put ur name there
Ristyo #6
Posted 24 March 2013 - 11:04 PM
One more, if you want to have the accounts get set by a variable (in this case x=read()) how to do it?
remiX #7
Posted 25 March 2013 - 12:16 AM
Well have it just insert into the table of accounts. Make sure you load all the accounts in the beggining and then ask register or login etc. And then if registeration is succesfull:
local user = read()
local password = read()
accounts[user] = password
Engineer #8
Posted 25 March 2013 - 01:03 AM
For your installer thing, you could use shell.run("pastebin get pbincode programname").
I've made a rip-off that program, so it doesnt display the text it produces:

function getPastebin( code, path ) -- Credits to the devs of CC
	local path = path or code
	local response = http.get(
		"http://pastebin.com/raw.php?i=" .. textutils.urlEncode( code )
		)
	if response then
		local contents = response.readAll()
		local file = fs.open( path, "w" )
		file.write( contents )
		file.close()
		return true
	else
		return false
	end
end

All credits go to the developers of ComputerCraft
Ristyo #9
Posted 25 March 2013 - 04:01 AM
Does this way work?
Stacking shell.run("pastebin get", pbin code, file name)
Its all stacked up to get each pastebin files
Will it work?
Example
shell.run("pastebin get", pbin code, file name1")
shell.run("pastebin get", pbin code, file name2")