No that would not be sufficient. you would need something like
write("Put stuff here")
local input = read()
local file = fs.open(directory/filename,"w") -- this opens the file in Write mode, if it's a file you can find just by typing programs into the shell, then you don't need the directory/
file.writeLine(input)
file.close() -- you must to this to close the file entirely and save it
--# That's your CREATING a password, to check you should do this
write("Input unlock")
local pass = read("*")
local file = fs.open(directory/filename,"r") -- opens the file in Read mode.
local fileData = {} -- declares fileData is an empty table. I use tables for lists like what could be in a file soooo
local line = file.readLine() -- reads the line
repeat
table.insert(fileData,line) -- inserts the line into the table fileData at the next slot
line = file.readLine() -- reads the next line
until line == nil -- eventually it will get to the end of the line, and the line = file.readLine() will be nil
file.close() -- closes the file again
if pass == fileData[1] then -- ASSUMING you put the password as the first line in the file it would then be put by the table.insert as the first spot which can be referenced as fileData[1]
--do stuff
else
--do more stuff
end
A little rundown, before i sleep and stuff. You set a variable to fs.open() which opens the file and leaves behind the variable as a handle to manipulate the file, or if you use peripherals a lot it's the same thing as doing peripheral.wrap(). There are 3 modes in fs.open() that i've used, and the correct syntax for fs.open is fs.open(string-filepath,string-mode) The modes are write, append, and read. Write (syntax is "w") clears the file entirely, and starts from the top. Append (syntax is "a") tacks on what you are putting in to the end of the program. Read (syntax is "r") allows you to read the file. When reading the file using file.readLine() if you want to read the next line, you need to specify it again by doing the same thing. It's like doing input = read(), when you look for input's value, you don't have to do another read().
There are many functions in the fs api, and a full list can be found
here.
I might update this when i wake, if you have any more questions or concerns, i will attempt to answer them when i can.
Edited by Dragon53535, 18 August 2014 - 07:14 AM.