[Lua] [Error] Simple Login System
#1
Posted 04 August 2012 - 10:00 AM
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 == ® then
print("Shutting Down...")
sleep(3)
os.shutdown()
elseif f == (q) then
write("Admin Mode")
end
#2
Posted 04 August 2012 - 10:03 AM
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 by luanub, 04 August 2012 - 10:07 AM.
#3
Posted 04 August 2012 - 10:27 AM
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
#4
Posted 05 August 2012 - 12:04 AM
I haven't tested this code yet, but most of it should work.
Let me know how it works
~Matt
#5
Posted 05 August 2012 - 03:55 PM
#6
Posted 05 August 2012 - 04:16 PM
#7
Posted 05 August 2012 - 04:33 PM
#8
Posted 05 August 2012 - 05:01 PM
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
#9
Posted 05 August 2012 - 05:04 PM
#10
Posted 05 August 2012 - 05:09 PM
#11
Posted 05 August 2012 - 05:13 PM
#12
Posted 05 August 2012 - 05:27 PM
#13
Posted 05 August 2012 - 05:39 PM
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
#14
Posted 05 August 2012 - 07:11 PM
#15
Posted 05 August 2012 - 09:11 PM
#16
Posted 06 August 2012 - 12:16 AM
#17
Posted 06 August 2012 - 01:01 AM
--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()
#18
Posted 06 August 2012 - 04:38 AM
#19
Posted 06 August 2012 - 10:39 PM
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











