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

table search and location confirm

Started by makerimages, 26 August 2012 - 07:48 AM
makerimages #1
Posted 26 August 2012 - 09:48 AM
hi, how should i do the following:

user is asked to enter a username and password(DONE)
the username and password are signed to a variable(DONE)


the parts i need help with:

the program should search a table named Usernames for the username var(lets say its called Uname)
and if it finds the Uname valu in the table it would save its location to a variable
and search a table named Passwords for the password var (Pword)
and if it finds that in a table then save its location in a another variable and then compare the two locations and if they Match then program does shell.run("something") if they dont match the user will be shown a error message and the program would start again
sjele #2
Posted 26 August 2012 - 10:08 AM

utable = {}
utable[1] = user1 --Username
utable[2] = user2 -- Username
utable[3] = user3  --Username
pwtable={}
pwtable[1] = pw1 --Pw goes here
pwtable[2] = pw2 --Add pw
pwtable[3] = pw3 --This is were you set the password
write("Username: ")
user = read()
term.clear()
term.setCursorPos(1, 1)
write("Password: ")
pw = read()
term.clear()
term.setCursorPos(1, 1)
for k,v in pairs(utable) do
	 if user == utable[v] then
	 u2 = utable[v]
	 break
  end
end
for j, k in pairs(pwtable) do
	 if pw == pwtable[k] then
	 pw2 = pwtable[k]
	 break
  end
end
if pw2 == pwtable[k] and u2 == utable[v] then
shell.run("something")
end

(Tesetd in CC emulator, should work. If not tell me as i made it it up just now)
Nvm this. Something messed up. Allways does sucsess thingy.
makerimages #3
Posted 26 August 2012 - 10:20 AM
:C what messed up? as i really need this
sjele #4
Posted 26 August 2012 - 10:23 AM
:C what messed up? as i really need this
If the pw and user did not match i still ran the something program i made, something printed sucsess if it was used. And it printed it, even tho i did not have right username / password.
makerimages #5
Posted 26 August 2012 - 10:26 AM
Could anyone help to fix it??
Kolpa #6
Posted 26 August 2012 - 11:49 AM
take a look at my airlock server programm: http://pastebin.com/DDniwcLY
makerimages #7
Posted 27 August 2012 - 08:45 AM
its not what i want, yours is rednet, mine is supposed to be one computer centered, could anyone come up with a code?
Kolpa #8
Posted 27 August 2012 - 04:03 PM
its not what i want, yours is rednet, mine is supposed to be one computer centered, could anyone come up with a code?
our purpose is to give you an idea of what to do your disability to change my code is not our problem