Jump to content




[Lua] [Error] Simple Login System


  • You cannot reply to this topic
18 replies to this topic

#1 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 04 August 2012 - 10: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 == ® then
print("Shutting Down...")
sleep(3)
os.shutdown()
elseif f == (q) then
write("Admin Mode")
end

#2 Luanub

    Lua Nub

  • Members
  • 1,135 posts
  • LocationPortland OR

Posted 04 August 2012 - 10: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 by luanub, 04 August 2012 - 10:07 AM.


#3 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 04 August 2012 - 10: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


#4 kotorone1

  • New Members
  • 20 posts

Posted 05 August 2012 - 12:04 AM

Here's strictly what you are looking fo
Spoiler
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

I haven't tested this code yet, but most of it should work.
Let me know how it works
~Matt

#5 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 03:55 PM

Thankyou, trying it out now. Ive been wanting to add the trys but i wasnt aware how to.

#6 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 04:16 PM

error on line 24, then expected?

#7 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 04:33 PM

error on line 19 too, then expected

#8 Xhisor

  • New Members
  • 37 posts
  • LocationSweden

Posted 05 August 2012 - 05: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


#9 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 05:04 PM

Thanks! ill try that out!

#10 Xhisor

  • New Members
  • 37 posts
  • LocationSweden

Posted 05 August 2012 - 05:09 PM

Make sure you have == and not = on all the lines you get "then expected".

#11 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 05:13 PM

OH i forgot about that

#12 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 05:27 PM

line 85, end expected to close function at line 19

#13 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 05 August 2012 - 05: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


#14 Xhisor

  • New Members
  • 37 posts
  • LocationSweden

Posted 05 August 2012 - 07: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.

#15 kotorone1

  • New Members
  • 20 posts

Posted 05 August 2012 - 09: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
edit: re-posted code, should be fixed now. Sorry that i didn't check this before i posted it.

#16 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 06 August 2012 - 12: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" ?

#17 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 06 August 2012 - 01: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()


#18 kotorone1

  • New Members
  • 20 posts

Posted 06 August 2012 - 04: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

#19 odd_kid

  • New Members
  • 35 posts
  • LocationProfessional Bug Finder, In San Antonio

Posted 06 August 2012 - 10: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?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users