252 posts
Posted 28 July 2012 - 06:05 PM
Hello, this is something that I would like to do.
It is a password thing, but I would like to edit it onto a floppy disk. What you would do is put the disk in the disk drive, have it auto install a program.
This program would be a password that you set at startup for the first time on the computer, even when the disk is removed. It would be like "Set your password" Or "What password do you want to use" ect… Then afterwards it would function as that password for the rest of the time. If you are feeling generous you could even add an option to be able to change the password… If you can help at all that would be nice. Thanks
797 posts
Posted 29 July 2012 - 11:37 AM
its easy enough…make it create a file with the password on it and then have the program read the password from the file…this would mean u can change It aswel
what's the code u have already?
127 posts
Posted 29 July 2012 - 12:29 PM
this will do what you want, hope it helps
Have as startup on a disk
if fs.exists("startup") == false then
fs.copy("disk/SecSystem","startup")
shell.run("startup")
end
Have this on a disk called like "SecSystem" or whatever u want it as just make sure u change the code above to match
function login()
term.clear()
term.setCursorPos(1,1)
print("Welcome To blah blah Security System")
write("Please Enter the Access Password: ")
pass = read("*")
local f = fs.open( "password.txt", "r" )
apass = f.readLine(newpass)
f:close()
if pass == apass then
-- your code here when pass is correct
else
-- your code here when pass is wrong
end
end
if fs.exists("password.txt") == false then -- this is the part that will set the password
term.clear()
term.setCursorPos(1,1)
print("Please Type a New Password")
newpass = read()
local f = fs.open( "password.txt", "w" )
f.write(newpass)
f:close()
login()
else
login()
end
1243 posts
Location
Indiana, United States
Posted 29 July 2012 - 01:33 PM
You need to put the code checking for a password at the top of the code, else it'll never check for the password.
252 posts
Posted 30 July 2012 - 04:19 PM
its easy enough…make it create a file with the password on it and then have the program read the password from the file…this would mean u can change It aswel
what's the code u have already?
I use a default code for a password off of this forum, just altered a bit to my needs… What I wanted to do is add some code onto it to make it have you set the password ingame for the first time… If you get what I mean…
109 posts
Posted 30 July 2012 - 06:12 PM
You can have my copy.
http://pastebin.com/fFgGgGJeThe settings file is unencrypted, but it is highly secure except for initial set up.
EDIT:
This also moves the current startup to startup.bak to prevent accidental overwrites, but only saves one .bak.
252 posts
Posted 04 September 2012 - 01:22 AM
its easy enough…make it create a file with the password on it and then have the program read the password from the file…this would mean u can change It aswel
what's the code u have already?
Uh, sorry, I haven't been able to connect to this site for about a month whatsoever.. The code that I have is…
os.pullEvent = os.pullEventRaw
local side = "left"
local password = "1412114"
term.clear()
term.setCursorPos(1,1)
write("nnnnnnPlease Enter The Password:nnnn> ")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Password Correct! Quarry Turned On!")
rs.setOutput(side,true)
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect! Quarry Not Turned On!")
sleep(2)
os.reboot()
end
local input = read()
if input == "reboot" then
write("ERROR: You may not reboot this computer at this time! nnTo Turn Off Quarry, Type Off")
elseif input == "Off" then
shell.run("quarryoff")
end
Yeah, I made a 'quarry lock' for a friend, and since I am a noob at Lua, I had it run external files at times…
Anyway, I understand the part where you are supposed to get the code to check for a password but the code that is needed is the code that I am asking for since I don't know it.
252 posts
Posted 04 September 2012 - 01:23 AM
its easy enough…make it create a file with the password on it and then have the program read the password from the file…this would mean u can change It aswel
what's the code u have already?
Uh, sorry, I haven't been able to connect to this site for about a month whatsoever.. The code that I have is…
os.pullEvent = os.pullEventRaw
local side = "left"
local password = "1412114"
term.clear()
term.setCursorPos(1,1)
write("nnnnnnPlease Enter The Password:nnnn> ")
local input = read("*")
if input == password then
term.clear()
term.setCursorPos(1,1)
print("Password Correct! Quarry Turned On!")
rs.setOutput(side,true)
else
term.clear()
term.setCursorPos(1,1)
print("Password incorrect! Quarry Not Turned On!")
sleep(2)
os.reboot()
end
local input = read()
if input == "reboot" then
write("ERROR: You may not reboot this computer at this time! nnTo Turn Off Quarry, Type Off")
elseif input == "Off" then
shell.run("quarryoff")
end
Yeah, I made a 'quarry lock' for a friend, and since I am a noob at Lua, I had it run external files at times…
Anyway, I understand the part where you are supposed to get the code to check for a password but the code that is needed is the code that I am asking for since I don't know it.
Also, this is old code now, this is just the password part, and when the password is correct, I make it toggle the redstone output rather than having a player type 'On or Off'. If that helps whatsoever.
252 posts
Posted 05 September 2012 - 03:37 PM
this will do what you want, hope it helps
Have as startup on a disk
if fs.exists("startup") == false then
fs.copy("disk/SecSystem","startup")
shell.run("startup")
end
Have this on a disk called like "SecSystem" or whatever u want it as just make sure u change the code above to match
function login()
term.clear()
term.setCursorPos(1,1)
print("Welcome To blah blah Security System")
write("Please Enter the Access Password: ")
pass = read("*")
local f = fs.open( "password.txt", "r" )
apass = f.readLine(newpass)
f:close()
if pass == apass then
-- your code here when pass is correct
else
-- your code here when pass is wrong
end
end
if fs.exists("password.txt") == false then -- this is the part that will set the password
term.clear()
term.setCursorPos(1,1)
print("Please Type a New Password")
newpass = read()
local f = fs.open( "password.txt", "w" )
f.write(newpass)
f:close()
login()
else
login()
end
I didn't see this post XD. Hey. Could you tell me what "f" means? Like 'local f'? Thanks, that would really help me :3
53 posts
Location
London, UK
Posted 05 September 2012 - 05:32 PM
'f' is just a variable.
In this case, 'f' has been assigned to 'fs.open()', meaning you don't have to type 'fs.open' every time - you can just type 'f'!
It's also used to make the code easier to read.
It doesn't matter what the name of the variable is as long as it's something logical, so you can remember what it is, but the name is case sensitive, so 'var' and 'Var' are completely different variables (in this case, 'f' probably stands for 'file', as 'fs.open()' is used to open the file directory in the brackets).
The 'local' part means that the variable is only used by this 'chunk' (part of) the code, and if you try to access 'f' in a different chunk, it won't be the same variable. This means that sections of code using variables with the same name won't interfere with each other. It is good habit to use local variables as much as possible.
252 posts
Posted 05 September 2012 - 10:46 PM
'f' is just a variable.
In this case, 'f' has been assigned to 'fs.open()', meaning you don't have to type 'fs.open' every time - you can just type 'f'!
It's also used to make the code easier to read.
It doesn't matter what the name of the variable is as long as it's something logical, so you can remember what it is, but the name is case sensitive, so 'var' and 'Var' are completely different variables (in this case, 'f' probably stands for 'file', as 'fs.open()' is used to open the file directory in the brackets).
The 'local' part means that the variable is only used by this 'chunk' (part of) the code, and if you try to access 'f' in a different chunk, it won't be the same variable. This means that sections of code using variables with the same name won't interfere with each other. It is good habit to use local variables as much as possible.
Ah thanks, this will help a lot. I didn't realize that you can do something like "[filename] = read()" and f.close, ect…