Jump to content




LUA [Help ASAP] Login program


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

#1 predatorxil

  • Members
  • 19 posts

Posted 17 October 2012 - 06:06 PM

Hello, im trying to add to program a limit of tries, so that if you input the password wrong 3 times it locks the computer for 30 sec. or anything you can do to help me, either way, must have a limit of 3 tries before it locks for 30sec or shutsdown. either way, plzzz help.

local sPath = ":/rom/programs"
term.clear()
term.setCursorPos(1,1)
print("==========================================================")
term.setCursorPos(1,2)
textutils.slowPrint("		   Welcome to R.S. Incorporated		   ")
term.setCursorPos(1,3)
print("=========================================================")
term.setCursorPos(1,5)
print("Users: ")
term.setCursorPos(1,6)
textutils.slowPrint("- predatorxil  - nexoigi")
term.setCursorPos(1,7)
textutils.slowPrint("- axel1298	 - ztrevetty88")
term.setCursorPos(1,8)
textutils.slowPrint("- coolwater97")
term.setCursorPos(1,9)
print("==========================================================")
term.setCursorPos(1,4)
textutils.slowPrint("Os Version 3.1")
term.setCursorPos(1,10)
textutils.slowPrint("Message: Enter UserName")
term.setCursorPos(1,11)
os.pullEvent = os.pullEventRaw
local tUsers = {}
tUsers["predatorxil"] = "13034"
tUsers["nexoigi"] = "999"
tUsers["coolwater97"] = "sarah1157"
tUsers["axel1298"] = "999"
while true do
	write("Username: ")
	name = read()
	if tUsers[name] then
   term.setCursorPos(10,10)
   textutils.slowPrint("Enter Password")
			term.setCursorPos(1,12)
			write("Password: ")
			pass = read("*")
			if tUsers[name] == pass then
	 term.setCursorPos(10,10)
	 textutils.slowPrint("Access Approved")
	 sleep(.5)
	 rs.setOutput("back", true)
	 sleep(5)
	 rs.setOutput("back", false)
	 sleep(1)
	 os.reboot()
			else
			end
	end
	term.setCursorPos(10,10)
textutils.slowPrint("Access Denied ")
	sleep(2)
	os.reboot()
end


























#2 sjele

  • Members
  • 334 posts
  • LocationSomewhere on the planet called earth

Posted 17 October 2012 - 06:15 PM

Each time they enter a wrong, pw make a counter go one up, when that counter reaces 3 do:
if count == 3 then
count = 0
sleep(30)
end


#3 Doyle3694

  • Members
  • 815 posts

Posted 17 October 2012 - 06:18 PM

rewrite the last part to this:
local tries = 0
local tUsers = {}
tUsers["predatorxil"] = "13034"
tUsers["nexoigi"] = "999"
tUsers["coolwater97"] = "sarah1157"
tUsers["axel1298"] = "999"
		write("Username: ")
		name = read()
		if tUsers[name] then
		   while true do
		   term.setCursorPos(10,10)
		   textutils.slowPrint("Enter Password")
						term.setCursorPos(1,12)
						write("Password: ")
						pass = read("*")
						if tUsers[name] == pass then
						   term.setCursorPos(10,10)
						   textutils.slowPrint("Access Approved")
						   sleep(.5)
						   rs.setOutput("back", true)
						   sleep(5)
						   rs.setOutput("back", false)
						   sleep(1)
						   os.reboot()
						else
						   if tries < 3 then
							   term.setCursorPos(10,10)
							   textutils.slowPrint("Access Denied ")
							   sleep(2)
							   tries = tries +1
						   else
							   print("Tried to many times")
							   print("Entering cooldown cycle")
							   sleep(30)
							   os.reboot()
						   end		  
						end
		end
end


different indentations in the same code is not good S:

#4 jag

  • Members
  • 533 posts
  • LocationStockholm, Sweden

Posted 17 October 2012 - 06:34 PM

View PostDoyle3694, on 17 October 2012 - 06:18 PM, said:

rewrite the last part to this:
Spoiler

different indentations in the same code is not good S:
WOA this alignment became really weird, this forum acts really strange when there's 4 spaces or more in a row...

#5 Ditto8353

  • New Members
  • 138 posts

Posted 17 October 2012 - 06:47 PM

View Postjag_e_nummer_ett, on 17 October 2012 - 06:34 PM, said:

WOA this alignment became really weird, this forum acts really strange when there's 4 spaces or more in a row...
To be honest I don't know why they use it. It's not even made for Lua syntax.

#6 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 17 October 2012 - 07:02 PM

Sometimes it makes the indentation neat and perfect, rest of the time it is just screwed up xD

#7 ChaddJackson12

  • Members
  • 264 posts

Posted 17 October 2012 - 07:24 PM

View PostDitto8353, on 17 October 2012 - 06:47 PM, said:

View Postjag_e_nummer_ett, on 17 October 2012 - 06:34 PM, said:

WOA this alignment became really weird, this forum acts really strange when there's 4 spaces or more in a row...
To be honest I don't know why they use it. It's not even made for Lua syntax.
Oh, that is why it seems so weird.. Huh..

#8 ChaddJackson12

  • Members
  • 264 posts

Posted 17 October 2012 - 07:26 PM

By the way, you do know that there can be a different screen size. So instead of just putting a certain number of ='s or whatever, use term.getSize. That can really help.

#9 Ditto8353

  • New Members
  • 138 posts

Posted 17 October 2012 - 07:30 PM

There is a fairly simple way to find out...
--Lua comment
//C/C++/C# comment
/*Multi-line
C comment*/
'VB comment...' or perhaps just a string...

Yup, made for C / C++ / C#





2 user(s) are reading this topic

0 members, 2 guests, 0 anonymous users