This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Maj_GsL_Inc.'s profile picture

Making a Multi Authentication Login System

Started by Maj_GsL_Inc., 29 June 2016 - 12:54 AM
Maj_GsL_Inc. #1
Posted 29 June 2016 - 02:54 AM

==========================================
My Goal
My goal is to create a login that requires multiple inputs to access the main terminal.
all my work i do my self but my knowledge is limited in Lua.
So far i have a the basics for what i want to do but it keeps on messing up for reasons i do not understand.
I am hoping someone can help me figure out what the issue is
NOTE: I do not want a "more efficient" code just some help to make it work


-- IronCore OS
  
-- Created By: GsL_Inc.
  
-- =====================
  
-- Anti-Bypass
  
	-- os.pullEvent = os.pullEventRaw
  
-- Data
  
	User = Majere
  
	Pass = GsL2c14Adm
  
	Aces = 9632
  
	TerminalCode = ICMA1A10
  
-- Center Text
  
	local cPrint = function(text)
  
		local x2,y2 = term.getCursorPos()
  
		local x,y = term.getSize()
  
		term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
  
		print(text)
  
	end
  
	local Clear = function()
  
		term.clear()
  
		term.setCursorPos(1, 1)
  
	end
  
-- Setup
  
		Clear()
  
	cPrint("Welcome to IronCore OS [Server [ICM-Main] ]")
  
	cPrint("===========================================")
  
	cPrint("Please Enter Username: ")
  
	term.setCursorPos(38, 3)
  
		input = read()
  
		if input == User then
  
	cPrint("Please Enter Password: ")
  
	term.setCursorPos(38, 4)
  
  end
  
  if input ~= User then
  
  cPrint("Access Denied!")
  
   sleep(2)
  
   shell.run("IronCore")
  
end
  
		input1 = read("*")
  
		if input1 == Pass then
  
	cPrint("Please Enter AcesCode: ")
  
	term.setCursorPos(38, 5)
  
  end
  
	 if input1 ~= Pass then
  
	 cPrint("Access Denied!")
  
	   sleep(2)
  
	   shell.run("IronCore")
  
end
  
		input2 = read("*")
  
		if input2 == Aces then
  
	cPrint("Checking Databanks")
  
	term.setCursosPos(x, y)
  
	textutils.slowWrite("................", 1)
  
		Clear()
  
	cPrint("Please Confirm Terminal Code")
  
	term.setCursorPos(x, y)
  
end
  
	if input2 ~= Aces then
  
  cPrint("Access Denied!")
  
	sleep(2)
  
	shell.run("IronCore")
  
end
  
		input3 = read()
  
		if input3 == TerminalCode then
  
	Clear()
  
	cPrint("Server [ICM-Main[AdminA]]")
  
	cPrint("=========================")
  
	cPrint(shell.run("programs"))
  
end
  
	if input3 ~= TerminalCode then
  
	  cPrint("Access Denied!")
  
		sleep(2)
  
		 shell.run("IronCore")
  
end

Thank you @Lupus590 you were actually helpful
Edited on 29 June 2016 - 12:55 PM
campicus #2
Posted 29 June 2016 - 11:01 AM
Oh gosh please format your code properly, I daresay you wont get any replies until you do.
Maj_GsL_Inc. #3
Posted 29 June 2016 - 02:39 PM
Post Removed [Because of Rant]

Sorry for the rant…
Edited on 29 June 2016 - 02:01 PM
Lupus590 #4
Posted 29 June 2016 - 02:48 PM

[./CODE]
code tags


this may help: https://www.lua.org/pil/4.3.2.html
Edited on 29 June 2016 - 12:51 PM
Maj_GsL_Inc. #5
Posted 29 June 2016 - 02:59 PM
Would it work if i said

while true do
[Code Here]
end
if not true then
[Other Code]
end

Sorry if that made no sense.
Bomb Bloke #6
Posted 30 June 2016 - 03:15 AM
Assuming you meant some arbitrary condition instead of "true", there'd be no need to use an "if" statement to test it once the loop ends - the fact that the loop has ended would be enough to tell you that it was no longer true.

Likewise, this sort of thing:

if input == User then
	-- match blah blah
end

if input ~= User then
	-- mismatch blah blah
end

… can be reduced using "else":

if input == User then
	-- match blah blah
else
	-- mismatch blah blah
end

You can nest your "if" statements (placing them inside each other):

while true do
	-- clear screen, show welcome blurb, ask for username
	
	input = read()
	if input == User then
		-- ask for password
		
		input = read()
		if input == Pass then
			-- ask for accesscode
			
			input = read()
			if input == Aces then
				-- ask for terminal code
				
				input = read()
				if input == TerminalCode then
					-- run "programs"
				end
			end
		end
	end
	
	-- display access denied, sleep for a bit
end

But your main problem probably boils down to this bit:

User = Majere
Pass = GsL2c14Adm
Aces = 9632
TerminalCode = ICMA1A10

You forgot to wrap quotes around "Majere", "GsL2c14Adm", "9632", and "ICMA1A10".

If you're still having issues, explain what's actually happening.
Maj_GsL_Inc. #7
Posted 30 June 2016 - 03:58 PM
Thanks for all the help i got it working so far.

The solution was pretty simple now that i see it i feel dumb

anyway thanks
Maj_GsL_Inc. #8
Posted 30 June 2016 - 08:48 PM
I created a login system that has a working code. But it spews out an error when i run it (it still works even with the error however).

I also know why the error happens (this is not why i am here but is relevant). The problem is when i change or remove the line that is causing the error it makes the code not work. In my knowledge this should not happen as the line is not crucial to the function of the code (to my knowledge). I will mark the line that is giving me trouble in the code below…

The error is that the cPrint function does not work with shell.run so it throws out an error (i think, though i may be wrong). I tried just normal print but this broke the code…..


-- IronCore OS
-- Created By: GsL_Inc.
-- =====================

-- Anti-Bypass
	--os.pullEvent = os.pullEventRaw

-- Data

	User = "Majere"
	Pass = "GsL2c14Adm"
	Aces = "9632"
	TerminalCode = "ICMA1-A-10"
  
-- Center Text

	local cPrint = function(text)
		local x2,y2 = term.getCursorPos()
		local x,y = term.getSize()
		term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
	  
		print(text)
	end
  
	local Clear = function()
		term.clear()
		term.setCursorPos(1, 1)
	end

while true do
Clear()
	cPrint("Welcome to IronCore OS [Server [ICM-Main] ]")
	cPrint("===========================================")
	cPrint("Please Enter Username: ")
		term.setCursorPos(38, 3)
	  
		input1 = read()
		if input1 == User then
	cPrint("Please Enter Password: ")
	term.setCursorPos(38, 4)
			  
				input2 = read("*")
				if input2 == Pass then
	cPrint("Please Enter AcesCode: ")
	term.setCursorPos(38, 5)
					  
						input3= read("*")
						if input3 == Aces then
	cPrint("Checking Databanks")
	term.setCursorPos(18, 7)
	textutils.slowWrite("..................", 1)
Clear()
	cPrint("Please Confirm Terminal Code: ")
	term.setCursorPos(49, 1)
								input4 = read()
								if input4 == TerminalCode then
	Clear()
	cPrint("Server [ICM-Main[AdminA]]")
	cPrint("=========================")
	cPrint(shell.run("programs"))  <== This is the line that gives the error,                                                                                                                                             when changed or removed                                                                                                                                                          the code does not work...
								end
						end
				end
		end
	  
		if input1 ~= User then
	 cPrint("Access Denied!")
				sleep(2)
				shell.run("IronCore")
		elseif input2 ~= Pass then
	 cPrint("Access Denied!")
				sleep(2)
				shell.run("IronCore")
		elseif input3 ~= Aces then
	 cPrint("Access Denied!")
				sleep(2)
				shell.run("IronCore")
		elseif input4 ~= TerminalCode then
	 cPrint("Access Denied!")
				sleep(2)
				shell.run("IronCore")
	   end
end

This code works as i intend other than that one line that throws out and error.
Edited on 30 June 2016 - 06:58 PM
ReBraLaCC #9
Posted 30 June 2016 - 09:37 PM
It seems that you're trying to get an output from the programs program, thats all… would say create your own program list thing or just let it run, because center aint working :)/>
Maj_GsL_Inc. #10
Posted 30 June 2016 - 09:40 PM
I know this, the problem is that even when i try to just normally print it (Which should work) the code ceases to work and when i change it back to cPrint("shell.run("programs") it works fine but throws an error about the cPrint…
Edited on 30 June 2016 - 07:41 PM
Lupus590 #11
Posted 30 June 2016 - 10:28 PM
what is the exact error?
AnotherName #12
Posted 30 June 2016 - 10:45 PM
shell.run("programs") return a boolean, so you aren't center the output of programs.

You not need execute "IronCore" again on each login attempt since you are in an infinite loop. Is important say that with each call to shell.run("IronCore") the stack grow, but will never decrease, so you will get a stack overflow error if I try login incorrectly many times.

Althought you change cPrint(shell.run("programs")) with shell.run("programs"), it work correctly, but it executes the login again quickly and seem that dosen't works.

you can use shell.programs() to get a table with all programs, and later center them

I think the next code, modified from yours, is what you are searching for.


-- IronCore OS
-- Created By: GsL_Inc.
-- =====================
-- Anti-Bypass
		--os.pullEvent = os.pullEventRaw
-- Data
		User = "Majere"
		Pass = "GsL2c14Adm"
		Aces = "9632"
		TerminalCode = "ICMA1-A-10"

-- Center Text
		local cPrint = function(text)
				local x2,y2 = term.getCursorPos()
				local x,y = term.getSize()
				term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
		
				print(text)
		end

		local Clear = function()
				term.clear()
				term.setCursorPos(1, 1)
		end
while true do
		Clear()
		cPrint("Welcome to IronCore OS [Server [ICM-Main] ]")
		cPrint("===========================================")
		cPrint("Please Enter Username: ")
  term.setCursorPos(38, 3)

  input1 = read()
  if input1 == User then
   cPrint("Please Enter Password: ")
   term.setCursorPos(38, 4)
		
   input2 = read("*")
   if input2 == Pass then
	cPrint("Please Enter AcesCode: ")
	term.setCursorPos(38, 5)
	input3= read("*")
	if input3 == Aces then
	 cPrint("Checking Databanks")
	 term.setCursorPos(18, 7)
	 textutils.slowWrite("....", 1)
	 Clear()
	 cPrint("Please Confirm Terminal Code: ")
	 term.setCursorPos(49, 1)
	 input4 = read()
	 if input4 == TerminalCode then
	  Clear()
	  cPrint("Server [ICM-Main[AdminA]]")
	  cPrint("=========================")
	
	  ----Change
	
	  textutils.tabulate(shell.programs())
	
	  break
	
	  -----
	 end
	end
   end
				 end
		
		 cPrint("Access Denied!")
		sleep(2)
end
Edited on 30 June 2016 - 08:52 PM
KingofGamesYami #13
Posted 30 June 2016 - 10:52 PM
I ran his code through sublime text's formatter. You're welcome.

Spoiler

-- IronCore OS
-- Created By: GsL_Inc.
-- =====================
-- Anti-Bypass
--os.pullEvent = os.pullEventRaw
-- Data
User = "Majere"
Pass = "GsL2c14Adm"
Aces = "9632"
TerminalCode = "ICMA1-A-10"

-- Center Text
local cPrint = function(text)
    local x2,y2 = term.getCursorPos()
    local x,y = term.getSize()
    term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)

    print(text)
end

local Clear = function()
    term.clear()
    term.setCursorPos(1, 1)
end
while true do
    Clear()
    cPrint("Welcome to IronCore OS [Server [ICM-Main] ]")
    cPrint("===========================================")
    cPrint("Please Enter Username: ")
    term.setCursorPos(38, 3)

    input1 = read()
    if input1 == User then
        cPrint("Please Enter Password: ")
        term.setCursorPos(38, 4)

        input2 = read("*")
            if input2 == Pass then
            cPrint("Please Enter AcesCode: ")
            term.setCursorPos(38, 5)

            input3= read("*")
                if input3 == Aces then
                cPrint("Checking Databanks")
                term.setCursorPos(18, 7)
                textutils.slowWrite("....", 1)
                Clear()
                cPrint("Please Confirm Terminal Code: ")
                term.setCursorPos(49, 1)
                input4 = read()
                    if input4 == TerminalCode then
                    Clear()
                    cPrint("Server [ICM-Main[AdminA]]")
                    cPrint("=========================")

                    ----Change

                    textutils.tabulate(shell.programs())

                    break

                    -----
                end
            end
         end
    end

    if input1 ~= User then
        cPrint("Access Denied!")
        sleep(2)
        --shell.run("IronCore")
    elseif input2 ~= Pass then
        cPrint("Access Denied!")
        sleep(2)
        --shell.run("IronCore")
    elseif input3 ~= Aces then
        cPrint("Access Denied!")
        sleep(2)
        --shell.run("IronCore")
    elseif input4 ~= TerminalCode then
        cPrint("Access Denied!")
        sleep(2)
        --shell.run("IronCore")
    end
end
Maj_GsL_Inc. #14
Posted 01 July 2016 - 12:16 AM
The reason i had it do the "access denied" over and over is because in my testing i removed the while loop. However i am very grateful for you help.

I have once again removed the loop and the break and the code works fine, thank you for all your help and if i need anymore help i shall come back :)/>
Bomb Bloke #15
Posted 01 July 2016 - 04:24 AM
Threads merged; please stick to the one thread for the one project.