Jump to content




[Lua][Question] A registrer system


7 replies to this topic

#1 stabby

  • Members
  • 16 posts

Posted 20 January 2013 - 05:32 AM

Hello all pros!

I'm working on a bank system where you enter your card and your pin.

So my idea is: Every card got an ID, and an unique pin. When you enter your pin and your card to the ATM machine the ATM machine is supposed to send the ID and the PIN to a server computer. The server computer will compare the pin and the ID with some kind of database. So all i want to do is a way for the server computer to add new users and reply to the atm machine with a boolean and a balance value.

I know how to do all of that except the registrer system.

Thanks for your answer!

#2 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 20 January 2013 - 05:51 AM

what if you hold all user info as a table inside a main table..
userdata = {}
function register(username,password)
  table.insert(userdata,{
    user = username,
    pass = password
    balance = 0
  }
end

that way you could just have it register in an easy function if the username isnt found in the database

#3 stabby

  • Members
  • 16 posts

Posted 20 January 2013 - 06:11 AM

View Postikke009, on 20 January 2013 - 05:51 AM, said:

what if you hold all user info as a table inside a main table..
userdata = {}
function register(username,password)
  table.insert(userdata,{
	user = username,
	pass = password
	balance = 0
  }
end

that way you could just have it register in an easy function if the username isnt found in the database

Yea i'm pretty sure i'm supposed to use a table but i'm not skilled enough to save it on a file and then make the computer search for the user and all that.. Thats pretty much my problem

#4 ikke009

  • Members
  • 224 posts
  • LocationSliding between sunbeams

Posted 20 January 2013 - 07:45 AM

I never tried saving things on files so I dont know how to do that.. but searching for the user is pretty easy..
for i,#userdata do --goes trough all the excisting places in the userdata table
  local u = userdata[i] --makes it more comprehensable
  if u then --if userdata[i] is not nil
    if diskuser == u.user then --if the username on the disk == username in the userdata table
	  do stuff login or whatever
    end
  end
end

go play with that and see what you can achieve

#5 mibac138

  • Members
  • 132 posts
  • LocationPoland

Posted 20 January 2013 - 07:52 AM

@up

I think this don't work maybe i write some code :)

for i=1,#userdata, 1 do
  local u = userdata[i]
  if u then
    if diskuser == u.user then
		  --[[For example]] print("Access granted!")
    end
  end
end


#6 ChunLing

  • Members
  • 2,027 posts

Posted 20 January 2013 - 09:42 AM

Just index the table by user. Then you don't have to search the table using a loop, you just check and see if there is an entry indexed by that user.

#7 remiX

  • Members
  • 2,076 posts
  • LocationSouth Africa

Posted 20 January 2013 - 10:10 AM

Try this for example, using fs api to write/read to/from files.

Spoiler


#8 dan14941

  • Members
  • 45 posts

Posted 20 January 2013 - 12:13 PM

do you want it to add people automatically?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users