34 posts
Location
Professional Bug Finder, In San Antonio
Posted 04 August 2012 - 11:00 AM
I have made a simple login system to access your computer, and ive been working hard on it. I want to add the options Reboot, Shutdown, and Adminmode. (bypass, no password)
there are errors and i cant figure out waht the problem is? Ive only been programming for a little. So yes. Can anyone fix the problem, or help me out?
term.clear()
o = "options"
p = "password"
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
pt = read("*")
if pt == (p) then
print("Logging In..")
sleep(2)
print("Login succesful!")
sleep(1)
print("Welcome user!")
sleep(2)
term.clear()
print("Starting odd OS…")
sleep(3)
print("Reading Files…")
sleep(2)
print("Clearing Cache…")
sleep(2)
print("Startup Succesful!")
sleep(1)
term.clear()
print("odd OS v1.4.7")
write("")
elseif p
else
print("Logging In…")
sleep(2)
print("Login Failed! Shutting Down…")
sleep(2)
os.shutdown()
end
s = "1"
r = "2"
q = "3"
if pt == (o) then
term.clear()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" =====================")
write("-")
f = read()
elseif f == (s) then
print("Rebooting…")
sleep(3)
os.reboot()
elseif f == (r) then
print("Shutting Down…")
sleep(3)
os.shutdown()
elseif f == (q) then
write("Admin Mode")
end
1111 posts
Location
Portland OR
Posted 04 August 2012 - 11:03 AM
What problems are you having with the code? And can you put code tags and maybe even spoiler tags around your code?
Some issues right off the bat that I see are
Line 33 starts an elseif statement but never finishes. The next line is and else. Remove it or finish the statement.
elseif p
Line 59, symbols such as that are not supports change the var to something else
elseif f == ® then
Edited on 04 August 2012 - 09:07 AM
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 04 August 2012 - 11:27 AM
Yeah sorry.
What im trying to do is; A login startup area, and at the same time i want to have a options area. So you type "options" and a menue comes up then you type "shutdown" and the computer shuts down. But i also want so that if you type a wrong password it doesnt let you in, which is immpossible to with the options part. I just need general help. the "elseif p" im not sure what that was going to be.
term.clear()
o = "options"
p = "password"
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
pt = read("*")
if pt == (p) then
print("Logging In..")
sleep(2)
print("Login succesful!")
sleep(1)
print("Welcome user!")
sleep(2)
term.clear()
print("Starting odd OS...")
sleep(3)
print("Reading Files...")
sleep(2)
print("Clearing Cache...")
sleep(2)
print("Startup Succesful!")
sleep(1)
term.clear()
print("odd OS v1.4.7")
write("")
elseif p
else
print("Logging In...")
sleep(2)
print("Login Failed! Shutting Down...")
sleep(2)
os.shutdown()
end
s = "1"
r = "2"
q = "3"
if pt == (o) then
term.clear()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" =====================")
write("-")
f = read()
elseif f == (s) then
print("Rebooting...")
sleep(3)
os.reboot()
elseif f == (r) then
print("Shutting Down...")
sleep(3)
os.shutdown()
elseif f == (q) then
write("Admin Mode")
end
20 posts
Posted 05 August 2012 - 01:04 AM
Here's strictly what you are looking fo
Spoiler
--startup display
function greet()
term.clear()
term.setCursorPos(1,1)
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
getInput()
end
function getInput()
local options = "options" --decalare possible choices
local pass = "password"
input = read("*")
if input = pass then
print("Logging In..")
sleep(2)
print("Login succesful!")
sleep(1)
print("Welcome user!")
sleep(2)
term.clear()
print("Starting odd OS...")
sleep(3)
print("Reading Files...")
sleep(2)
print("Clearing Cache...")
sleep(2)
print("Startup Succesful!")
sleep(1)
term.clear()
shell.run() --default page of your OS here
print("odd OS v1.4.7") --delete this once you have the real homepage made
elsif input = options then
optionsMenu()
else
print("Logging In...")
sleep(2)
print("Login Failed! Shutting Down...")
sleep(2)
os.shutdown()
end
end
function optionsMenu()
local op1 = 1
local op2 = 2
local op3 = 3
term.clear()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" || 4 Back to login||")
print(" =====================")
write("-")
input2 = read()
if input2 = op1 then
print("Rebooting...")
sleep(3)
os.reboot()
elseif input2 = op2
print("Powering down...")
sleep(3)
os.shutdown()
elseif input = op3 then)
print("Admin Mode")
end
end
greet()
But, I personally would advise against using that code.It has extremely long sleep() times, which will anoy a user. Also, having the computer reboot the first time you mess up is slightly cruel. Instead, i would recommend this code
Spoiler
--prevent ctrl+t escape
os.pullEvent = os.pullEventRaw
--declare fail count
failcount = 0
--startup display
function greet()
term.clear()
term.setCursorPos(1,1)
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
getInput()
end
function getInput()
while true do --Im using this instead of recursion (ie using getInput() at the comment) so as to prevent any weird
--java exceptions stemming from the use of recursion
local options = "options" --decalare possible choices
local pass = "password"
input = read("*")
if input = pass then
print("Logging In..")
sleep(.25)
print("Login succesful: Welcome user!")
sleep(2) --probably reduce this sleep
term.clear()
print("Starting odd OS...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
shell.run() --default page of your OS here
print("odd OS v1.4.7") --delete this once you have the real homepage made
elsif input = options then
optionsMenu()
else
print("Logging In...")
if failcount > 4 then --check to make sure you havent already failed 4 times
print("Failed to log in. Powering down.")
sleep(1)
os.shutdown()
else -- increase failcount to n+1
failcount = failcount + 1
term.scroll(-1)
print("Incorrect paswword")
term.scroll(1)
sleep(1)
term.scroll(-1)
term.clearLine()
term.scroll(1)
--its possible to use getInput() here instead
end
end
end
function optionsMenu()
local op1 = 1
local op2 = 2
local op3 = 3
term.clear()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" || 4 Back to login||")
print(" =====================")
write("-")
input2 = read()
if input2 = op1 then
print("Rebooting...")
sleep(.5)
os.reboot()
elseif input2 = op2
print("Powering down...")
sleep(.5)
os.shutdown()
elseif input = op3 then)
print("Admin Mode")
end
end
greet()
I haven't tested this code yet, but most of it should work.
Let me know how it works
~Matt
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 04:55 PM
Thankyou, trying it out now. Ive been wanting to add the trys but i wasnt aware how to.
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 05:16 PM
error on line 24, then expected?
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 05:33 PM
error on line 19 too, then expected
37 posts
Location
Sweden
Posted 05 August 2012 - 06:01 PM
No, no, no! The options menu should be coded like this!
function optionsMenu()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" || 4 Back to login||")
print(" =====================")
write("-")
local event, input2 = os.pullEvent("char")
if input2 == "1" then
print("Rebooting...")
sleep(3)
os.reboot()
elseif input2 == "2" then
print("Powering down...")
sleep(3)
os.shutdown()
elseif input2 == "3" then
print("Admin Mode")
elseif input2 == "4" then
term.clear()
term.setCursorPos(1,1)
greet()
end
end
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 06:04 PM
Thanks! ill try that out!
37 posts
Location
Sweden
Posted 05 August 2012 - 06:09 PM
Make sure you have == and not = on all the lines you get "then expected".
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 06:13 PM
OH i forgot about that
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 06:27 PM
line 85, end expected to close function at line 19
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 05 August 2012 - 06:39 PM
Not working at all.
Sometimes I reboot, and it just doesnt do anything. Now its fucntion at line 89 end expected.
--prevent ctrl+t escape
os.pullEvent = os.pullEventRaw
--declare fail count
failcount = 0
--startup display
function greet()
term.clear()
term.setCursorPos(1,1)
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
getInput()
end
function getInput()
while true do --Im using this instead of recursion (ie using getInput() at the comment) so as to prevent any weird
--java exceptions stemming from the use of recursion
local options = "options" --decalare possible choices
local pass = "password"
input = read("*")
if input == (pass) then
print("Logging In..")
sleep(.25)
print("Login succesful: Welcome user!")
sleep(2) --probably reduce this sleep
term.clear()
print("Starting odd OS...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
shell.run() --default page of your OS here
print("odd OS v1.4.7") --delete this once you have the real homepage made
elsif input == "options" then
optionsMenu()
else
print("Logging In...")
if failcount > 4 then --check to make sure you havent already failed 4 times
print("Failed to log in. Powering down.")
sleep(1)
os.shutdown()
else -- increase failcount to n+1
failcount = failcount + 1
term.scroll(-1)
print("Incorrect paswword")
term.scroll(1)
sleep(1)
term.scroll(-1)
term.clearLine()
term.scroll(1)
--its possible to use getInput() here instead
end
end
end
function optionsMenu()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" || 4 Back to login||")
print(" =====================")
write("-")
local event, input2 = os.pullEvent("char")
if input2 == "1" then
print("Rebooting...")
sleep(3)
os.reboot()
elseif input2 == "2" then
print("Powering down...")
sleep(3)
os.shutdown()
elseif input2 == "3" then
print("Admin Mode")
elseif input2 == "4" then
term.clear()
term.setCursorPos(1,1)
greet()
end
end
37 posts
Location
Sweden
Posted 05 August 2012 - 08:11 PM
Thats because you wrote "elsif" on row 37 and not "elseif". You also have to add a third end and then greet() after that.
20 posts
Posted 05 August 2012 - 10:11 PM
Sorry, as i said, i programmed this in ten minutes, as a rough idea. And forgetting the == was just stupid, i should have checked my code for that before i posted.
Spoiler
--prevent ctrl+t escape
os.pullEvent = os.pullEventRaw
--declare fail count
failcount = 0
tTrue = true
--startup display
function greet()
term.clear()
term.setCursorPos(1,1)
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
getInput()
end
function getInput()
while tTrue == true do --Im using this instead of recursion (ie using getInput() at the comment) so as to prevent any weird
--java exceptions stemming from the use of recursion
local options = "options" --decalare possible choices
local pass = "password"
input = read("*")
if input == pass then
print("Logging In..")
sleep(.25)
print("Login succesful: Welcome user!")
sleep(2) --probably reduce this sleep
term.clear()
term.setCurorPos(1,1)
print("Starting odd OS...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
tTrue = false
--shell.run() --default page of your OS here
print("odd OS v1.4.7") --delete this once you have the real homepage made
elseif input == options then
tTrue = false
optionsMenu()
else
print("Logging In...")
if failcount > 4 then --check to make sure you havent already failed 4 times
print("Failed to log in. Powering down.")
sleep(1)
os.shutdown()
else -- increase failcount to n+1
failcount = failcount + 1
term.scroll(-1)
print("Incorrect paswword")
term.scroll(1)
sleep(1)
term.scroll(-1)
term.clearLine()
term.scroll(1)
--its possible to use getInput() here instead
end
end
end
end
function optionsMenu()
local op1 = "1"
local op2 = "2"
local op3 = "3"
term.clear()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" || 4 Back to login||")
print(" =====================")
write("-")
local event, input2 = os.pullEvent("char")
if input2 == "1" then
print("Rebooting...")
sleep(3)
os.reboot()
elseif input2 == "2" then
print("Powering down...")
sleep(3)
os.shutdown()
elseif input2 == "3" then
print("Admin Mode")
elseif input2 == "4" then
term.clear()
term.setCursorPos(1,1)
greet()
end
end
greet()
edit: re-posted code, should be fixed now. Sorry that i didn't check this before i posted it.
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 06 August 2012 - 01:16 AM
Great work on the code koto! and thankyou for the input xoph, Last question befor i realease 1.5, how do i make it so if they push any number but 1-5 it says something like "not a valid input" ?
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 06 August 2012 - 02:01 AM
ALSO, i type in the password and says logging in, but it doesnt go to the normal shell, why? Code:
--prevent ctrl+t escape
os.pullEvent = os.pullEventRaw
--declare fail count
failcount = 0
tTrue = true
--startup display
function greet()
term.clear()
term.setCursorPos(1,1)
print(" odd Security v1.5 (beta) ")
print(" =========================")
print(" || UserName: yourname ||")
print(" || Password: ******** ||")
print(" =========================")
print(" ||Type options for opt.||")
print(" =========================")
write(" Password: ")
getInput()
end
function getInput()
while tTrue == true do --Im using this instead of recursion (ie using getInput() at the comment) so as to prevent any weird
--java exceptions stemming from the use of recursion
local options = "options" --decalare possible choices
local pass = "password"
input = read("*")
if input == (pass) then
print("Logging In..")
sleep(.25)
print("Login succesful: Welcome user!")
sleep(2) --probably reduce this sleep
term.clear()
term.setCurorPos(1,1)
print("Starting odd OS...")
sleep(1)
term.clear()
term.setCursorPos(1,1)
--shell.run() --default page of your OS here
print("odd OS v1.4.7") --delete this once you have the real homepage made
elseif input == options then
tTrue = false
optionsMenu()
else
print("Logging In...")
if failcount > 4 then --check to make sure you havent already failed 4 times
print("Failed to log in. Powering down.")
sleep(1)
os.shutdown()
else -- increase failcount to n+1
failcount = failcount + 1
term.scroll(-1)
print("Incorrect paswword")
term.scroll(1)
sleep(1)
term.scroll(-1)
term.clearLine()
term.scroll(1)
--its possible to use getInput() here instead
end
end
end
end
function optionsMenu()
local op1 = "1"
local op2 = "2"
local op3 = "3"
term.clear()
print(" =====================")
print(" || Options Menu ||")
print(" =====================")
print(" || 1 Reboot ||")
print(" || 2 Shutdown ||")
print(" || 3 Admin Mode ||")
print(" || 4 Back to login||")
print(" =====================")
write("-")
local event, input2 = os.pullEvent("char")
if input2 == "1" then
print("Rebooting...")
sleep(3)
os.reboot()
elseif input2 == "2" then
print("Powering down...")
sleep(3)
os.shutdown()
elseif input2 == "3" then
print("Admin Mode")
elseif input2 == "4" then
term.clear()
term.setCursorPos(1,1)
greet()
end
end
greet()
20 posts
Posted 06 August 2012 - 05:38 AM
Its because it doesnt run anything, and just sits there. once you give the shell.run() a program to run, and take away the comment code, it will go do something. Because it has nothing to run, it will stay in the "while tTrue do" loop. Anyway, i added another update that will break the program after the password is entered
34 posts
Location
Professional Bug Finder, In San Antonio
Posted 06 August 2012 - 11:39 PM
Well i wasnt planning on making a WHOLE os just yet, how can I make it so it just goes straight to the CraftOS shell?