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

DoorLock V1

Started by XxCreepydeaDxX, 19 July 2014 - 12:11 PM
XxCreepydeaDxX #1
Posted 19 July 2014 - 02:11 PM
Hello there ! i want to share my first program called DoorLock v1 . i think you know it . it's a doorlock program i'm new to computercraft so i don't really know how to code but im proud of that program .

there is the pastebin for it : http://pastebin.com/WWiPfWwY
just type that in a computer : pastebin get WWiPfWwY startup
the default password is : admin
for changing it edit the program ( ctrl + t ; edit startup ) at line 7 : "if mdp == ("admin") then" just remove "admin "and type your password

How to setup :



sorry for my english :P/>
XxCreepydeaDxX #2
Posted 19 July 2014 - 06:24 PM
My bad . can somebody move this post in the "program section" ?
Arektor #3
Posted 19 July 2014 - 07:19 PM
Well, it's pretty simple but for a first program I'll never did better ^^
If you want to make a V2, take a look at these pages:
http://www.computerc...56-in-pure-lua/ to hash the password and make it harder to hack (maybe a bit too hard to understand for somebody is new in lua / computercraft, but maybe…)
http://www.computerc...nfo/wiki/Tables could be useful for making several accounts

And hilburn gave me these functions for one of my programs, it's very cool, you can save a table in a file, and load it later.

--All credits to hilburn for these two functions
function saveFile(data, filename)
	  if fs.exists(filename) then
		 fs.delete(filename)
	  end
	  file = fs.open(filename, "w")
	  file.write(textutils.serialize(data))
	  file.close()
end
function loadFile(filename)
	   if fs.exists(filename) then
		  file = fs.open(filename, "r")
		  data = textutils.unserialize(file.readAll())
		  file.close()
				else
		   print("Could not load data file, exiting...")
		   sleep(1.4)
		   os.shutdown()
		end
				return data
end

A little explication of these functions:
You have a file called "passwords" and contain the following code :

{
"password1";
"password2";
"Nuttela";
"Sugar";
}
This is a table structure.

You want to load it in the program called "DoorLock", as the table "list", you juste have to did that :
local list = loadFile("passwords")
Notice if, for example, your file "passwords" is in the folder Door, it will be this :
local list = loadFile("/Door/passwords")

Next, if you want to save the file (For example, somebody modified his password in the program):
saveFile(list, "passwords") where list is the name of your table and passwords the name of your file.

I hope I've tell you something useful, and you've understand it (if not, just tell me it, I'll do some… better explications)
And if you want the hilburn's functions adapted for a simple string and not a table, tell me it too :P/>

Edit: After reflexion I think I've said a lot of things that you will not understand X_X
Edited on 19 July 2014 - 05:20 PM
XxCreepydeaDxX #4
Posted 19 July 2014 - 08:45 PM
Well, it's pretty simple but for a first program I'll never did better ^^
If you want to make a V2, take a look at these pages:
http://www.computerc...56-in-pure-lua/ to hash the password and make it harder to hack (maybe a bit too hard to understand for somebody is new in lua / computercraft, but maybe…)
http://www.computerc...nfo/wiki/Tables could be useful for making several accounts

And hilburn gave me these functions for one of my programs, it's very cool, you can save a table in a file, and load it later.

--All credits to hilburn for these two functions
function saveFile(data, filename)
	  if fs.exists(filename) then
		 fs.delete(filename)
	  end
	  file = fs.open(filename, "w")
	  file.write(textutils.serialize(data))
	  file.close()
end
function loadFile(filename)
	   if fs.exists(filename) then
		  file = fs.open(filename, "r")
		  data = textutils.unserialize(file.readAll())
		  file.close()
				else
		   print("Could not load data file, exiting...")
		   sleep(1.4)
		   os.shutdown()
		end
				return data
end

A little explication of these functions:
You have a file called "passwords" and contain the following code :

{
"password1";
"password2";
"Nuttela";
"Sugar";
}
This is a table structure.

You want to load it in the program called "DoorLock", as the table "list", you juste have to did that :
local list = loadFile("passwords")
Notice if, for example, your file "passwords" is in the folder Door, it will be this :
local list = loadFile("/Door/passwords")

Next, if you want to save the file (For example, somebody modified his password in the program):
saveFile(list, "passwords") where list is the name of your table and passwords the name of your file.

I hope I've tell you something useful, and you've understand it (if not, just tell me it, I'll do some… better explications)
And if you want the hilburn's functions adapted for a simple string and not a table, tell me it too :P/>

Edit: After reflexion I think I've said a lot of things that you will not understand X_X

thx for explaining me some things . I don't really understand but i'm gonna try to do what you have say ;)/>

sorry for the english
Dragon53535 #5
Posted 20 July 2014 - 04:00 AM
Hes using the file commands, i'm going to link you to a little introduction to the commands you can use to save a config. Here Using that you could type something like:

local file = fs.open("config","r") --opens a file.
local fileData = {} --This is a new table to save the data in.
local line = file.readLine() -Reads a line in the file.
repeat
   table.insert(line,fileData) --Puts the line into the table to be read.
   line = file.readLine() --Reads the next line
until line == nil --when no more lines, stops trying to read lines.
file.close() -- closes the file, you need to do this after you're done using a file.
local Input = read()
If Input == fileData[1] then -- If what you type is the first line in the file then let them in.
  rs.setOutput("back",true)
end

Now if you wanted to you could attempt to look at one of the programs i made earlier myself, however i use GravityScore's SHA256 for computercraft in my program, so you have to read past it if you want to see how my program works. I use functions and a few other things that might be a tiny bit difficult to understand fully when you're just starting out however if you look for the fs.open area you can see how i apply that. http://pastebin.com/gai9NPjN The way the program is set up is that people have a username and password to login with, and an admin account that decides if they can access the computer fully.
Edited on 21 July 2014 - 11:12 AM
Arektor #6
Posted 20 July 2014 - 06:00 PM
sorry for the english

I'm not english too ^^

And you can make a little GUI too, using Paint (in computercraft) and this :

image = paintutils.loadImage("/Images/Menu") --Menu is the image file, located in the Images folder. If the image is in the root folder, just type "Menu".
paintutils.drawImage(image,1,1) --Will draw the image at the coords X: 1 and Y: 1.
Cookiezi #7
Posted 20 July 2014 - 06:03 PM
Nice job, I like it.
I can use this on CC servers, it will be handy.
XxCreepydeaDxX #8
Posted 21 July 2014 - 10:29 AM
Nice job, I like it.
I can use this on CC servers, it will be handy.
yes you can ! why not :)/>

Hes using the file commands, i'm going to link you to a little introduction to the commands you can use to save a config. Here Using that you could type something like:

local file = fs.open("config","r") --opens a file.
local fileData = {} --This is a new table to save the data in.
local line = file.readLine() -Reads a line in the file.
repeat
   table.insert(line,fileData) --Puts the line into the table to be read.
   line = file.readLine() --Reads the next line
until line == nil --when no more lines, stops trying to read lines.
file.close() -- closes the file, you need to do this after you're done using a file.
local Input = read()
If Input == fileData[1] then -- If what you type is the fire line in the file then let them in.
  rs.setOutput("back",true)
end

Now if you wanted to you could attempt to look at one of the programs i made earlier myself, however i use GravityScore's SHA256 for computercraft in my program, so you have to read past it if you want to see how my program works. I use functions and a few other things that might be a tiny bit difficult to understand fully when you're just starting out however if you look for the fs.open area you can see how i apply that. http://pastebin.com/gai9NPjN The way the program is set up is that people have a username and password to login with, and an admin account that decides if they can access the computer fully.
wow you program is literally different . im gonna check it out

sorry for the english

I'm not english too ^^

And you can make a little GUI too, using Paint (in computercraft) and this :

image = paintutils.loadImage("/Images/Menu") --Menu is the image file, located in the Images folder. If the image is in the root folder, just type "Menu".
paintutils.drawImage(image,1,1) --Will draw the image at the coords X: 1 and Y: 1.
i know that . but i don't think i'm gonna make it . i don't really love the computercraft's Paint
Edited on 21 July 2014 - 08:28 AM
Dragon53535 #9
Posted 21 July 2014 - 01:10 PM
wow you program is literally different . im gonna check it out

Yeah it saves the file with the persons username as the file name and the password as a hashed string inside the file.
Carrots084 #10
Posted 26 July 2014 - 04:12 AM
Good Job! When I started Lua I couldn't do squat! You're on your way to a great place! Keep programming!