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

[Solved] Search for a name in a table

Started by Oct125, 26 December 2012 - 08:07 AM
Oct125 #1
Posted 26 December 2012 - 09:07 AM
Hello, i'm making a login program and i want multi-user, so, i will put all names and password in a table, ok. But i don't know how to compare the user input with the values in the table… Someone can help me?
Cozzimoto #2
Posted 26 December 2012 - 09:19 AM
ive made a door authentication server where all the ids of the computers registered to the server and the passwords that go to them

id make two tables one for the ids, and another for the passwords


id = {}
pass = {}

then within a server use a for loop to compare the ids with the passwords. and i use this method so no one can hack into my server
and when i say server im transmitting the user input of the client to the server with rednet.
and when the request is sent it waits to get a reply

maybe something you can shoot for.

i dont want to give out my code but i will give you the idea of how i went around it. if your confused ask me your questions =D
Oct125 #3
Posted 26 December 2012 - 09:24 AM
Well… I need to compare the content of the table with the user input in the login form
NDFJay #4
Posted 26 December 2012 - 09:27 AM
this should have all the information you need

>> Link <<
Cozzimoto #5
Posted 26 December 2012 - 09:28 AM
yea something like


id = {123,527,233}
pass = {"test1","test2","test3"}

event,p1,p2,p3 = os.pullEvent()

for i=1,#id do
  if id == p1 and pass == p2 then
    profit!
  end
end

you take in what was sent from what computer and compare it to whatever the message was and if they both match then success!
Oct125 #6
Posted 26 December 2012 - 09:37 AM
this should have all the information you need

>> Link <<

Well, i saw this example… But i don't see the part of the code what i need :S

yea something like


id = {123,527,233}
pass = {"test1","test2","test3"}

event,p1,p2,p3 = os.pullEvent()

for i=1,#id do
  if id == p1 and pass == p2 then
	profit!
  end
end

you take in what was sent from what computer and compare it to whatever the message was and if they both match then success!

Ok! This is exactly what i need! Thanks!
Cozzimoto #7
Posted 26 December 2012 - 09:41 AM
you are quite welcome. i learn by just writing my code all by myself, but i am here to teach as well =D

EDIT
another thing that may be very fun to do is if the client sends back a failed message meaning the password didnt match what you sent you can have it send a redstone signal thats hiding under the users feet to drop them into lava or some sort of way to kill them saying they are not allowed, or a safer way would keep track of how many attemps and if the failed attempts equals lets say 3 then drop them. >=)
Edited on 26 December 2012 - 08:44 AM
remiX #8
Posted 26 December 2012 - 09:44 AM
I'd suggest to not use tables, rather use a file system (save all users and there passwords to a file of their own
Save the names and passwords of everyone to a file.

Your file system can be like so:

.OS (main directory)
  .users (directory for all users)
    Oct125 (users)

To check if the user is valid, you use repeat to check every line of the file:


write("Username: ")
userName = read()

if fs.exists(".OS/.users/" .. userName) then
    -- code if the user exists
    -- now enter password, etc
else
    -- user does not exist
end
Oct125 #9
Posted 26 December 2012 - 09:45 AM
:D/> Thanks the code will help a lot!
Cozzimoto #10
Posted 26 December 2012 - 09:46 AM
yea you could do that but he was just asking the basic fundamentals of how to get it working. lol =P

thats what i got on mine, but i need to write another server to register a new computer on the database, that be pretty cool. =)
Oct125 #11
Posted 26 December 2012 - 09:50 AM
you are quite welcome. i learn by just writing my code all by myself, but i am here to teach as well =D

EDIT
another thing that may be very fun to do is if the client sends back a failed message meaning the password didnt match what you sent you can have it send a redstone signal thats hiding under the users feet to drop them into lava or some sort of way to kill them saying they are not allowed, or a safer way would keep track of how many attemps and if the failed attempts equals lets say 3 then drop them. >=)

:D/> Thanks the code will help a lot! And this is a good idea to keep others away from my house >:)/>


I'd suggest to not use tables, rather use a file system (save all users and there passwords to a file of their own
Save the names and passwords of everyone to a file.

Your file system can be like so:

.OS (main directory)
  .users (directory for all users)
	Oct125 (users)

To check if the user is valid, you use repeat to check every line of the file:


write("Username: ")
userName = read()

if fs.exists(".OS/.users/" .. userName) then
	-- code if the user exists
	-- now enter password, etc
else
	-- user does not exist
end

Well, that's a good idea, i'll think about it…
Cozzimoto #12
Posted 26 December 2012 - 09:55 AM
yea, whenever you get a system working and finished get with me because id love to see what you came up with and how you went about it =)