Posted 08 November 2012 - 10:12 AM
I'm trying to make a nuclear reactor controller but I have problems with a password protecting it.
When i run my code it first updates to the newest pastebin version (thanks Cranium).
After that it asks for a password, and after bypassing the password I would like the user to be able to type "lock" and then lock the computer, although I can't figure it out…
I miss a goto command, I know there is something called "functions" but I can't seem to figure it out, also while I'm at it, will it be possible to let the computer process redstone input/output while locked?
Thanks in advantage :P/>/>
Code:
When i run my code it first updates to the newest pastebin version (thanks Cranium).
After that it asks for a password, and after bypassing the password I would like the user to be able to type "lock" and then lock the computer, although I can't figure it out…
I miss a goto command, I know there is something called "functions" but I can't seem to figure it out, also while I'm at it, will it be possible to let the computer process redstone input/output while locked?
Thanks in advantage :P/>/>
Code:
Spoiler
local version =
0.01
local pastebinlink = "5rALib9G" --The pastebin "code"
local password = "123bacon" -- The password required to unlock the computer
trys = 3 -- The number of trys before anti bruteforce
bruteforcetime = 18 -- The amount of time the antibruteforce should take
--check version by Cranium
term.clear()
term.setCursorPos(1,1)
print("Program loading...")
print("Current version: "..version)
local updateSite = http.get("http://pastebin.com/raw.php?i="..pastebinlink)
updateSite.readLine()
local coding = updateSite.readLine()
local newVersion = (tonumber(coding))
sleep(2)
if tonumber(newVersion) > version then
print("Newest version is: "..newVersion)
print("Update required. Updating now...")
local updateSite = http.get("http://pastebin.com/raw.php?i="..pastebinlink)
local siteFile = updateSite.readAll()
local writeFile = fs.open(shell.getRunningProgram(),"w")
writeFile.write(siteFile)
writeFile.close()
print("The program will now restart your computer.")
sleep(2)
os.reboot()
end
--Password protection
tryerror = trys
locked = true
while locked == true do
term.clear()
term.setCursorPos(1,1)
print("Please enter the password:")
input = read("*")
if input == password then
print("Welcome")
tryerror = trys
sleep(1)
locked = false
else
print("PASSWORD INCORRECT!")
tryerror = tryerror - 1
sleep(2)
if tryerror < 1 then
print("Brute Force Detected")
sleep(bruteforcetime)
tryerror = trys
end
end
end
--Beyond protection
term.clear()
term.setCursorPos(1,1)
print("+--------------------{NewkOS}--------------------+\n")
input = read()
if input == "version" then
print("Current version: "..version)
elseif input == "lock" then
locked = true
end