Jump to content




banking system help

help

17 replies to this topic

#1 xbsktball10x

  • Members
  • 26 posts

Posted 30 June 2013 - 09:49 PM

Im working on a banking system and i just finished up the code to add a new account. My problem is that if someone chooses a pin that is the same as someone else it will return that they also have the same account # as the person that has the same pin as them. heres the code

client
term.clear()
term.setCursorPos(1,1)
rednet.open("left")
local successfullogin = false
print("welcome to the bank")
print("1] login")
print("2] create new account")
print("3] shutdown")
write(">")
local firstoption = read()
  if firstoption == "1" then
	rednet.send(51,"login", true)
	write("account number: ")
	local accountnumb = read()
	write("pin: ")
	local pinnumb = read("*")
	rednet.send(51, accountnumb, true)
	local senderId, message, distance = rednet.receive(5)
	print(message)
	senderId, message, distance = rednet.receive()
	  if pinnumb == message then
		successfullogin=true
	  end
  elseif firstoption == "2" then
	rednet.send(51, "create new account", true)
	write("Enter a 4 digit pin for your account: ")
	local pin = read("*")
	rednet.send(51,pin, true)
	localaccountsenderId, accountnumber, accountdistance = rednet.receive()
	write("Your account number is: "..accountnumber)
  sleep(2)
  elseif firstoption == "3" then
	print("shutting down...")
	sleep(1)
	os.shutdown()
	else
  print("unsuccessful login")
  sleep(1)
  end
function menu()
print("1) withdraw")
print("2) deposit")
print("3) wire tranfer")
print("4) balance inquiry")
print("5) logoff")
write("Enter a number: ")
local option = read()
   if option == "1" then
   print("Enter go back to go back to the menu")
   write("How much? ")
   local amount = read()
	 if amount == "go back" then
	 menu()
	 else
	 rednet.send(51, "withdraw", true)
	 rednet.send(51, amount, true)
	 print("withdrawing funds...")
	 print("gold will be in withdraw area")
	 sleep(1)
	 menu()
   end
   elseif option == "2" then
	 write("Do you want to deposit? y/n")
	 local deposit = read()
	   if deposit == "y" then
		 rednet.send(51,"deposit", true)
		 else
		 menu()
	   end  
   elseif option =="3" then
	 --wire transfer code
   elseif option == "4" then
	 rednet.send(51, "balance", true)
	 local senderidbalance, balancemessage, distancebalance = rednet.receive()
	 print(balancemessage)
   elseif option == "5" then
	 shell.run("startup")
   else
	 print("That isn't a selection")
	 sleep(1)
   end
   sleep(2)
   menu()
  end
if successfulogin == true then
rednet.send(51, "validuser", true)
menu()
else
term.clear()
term.setCursorPos(1,1)
shell.run("startup")
end

server

print("This is the account server")
print("If you need to add an account then please do so through the admin computer in the server rooom")
print("Do not restart ever")
print("If you restart then all of the accounts and pins will be lost")
local pins = ""
local accounts= ""
local accountsId = ""
local realaccount = false
local accountaccess = false
rednet.open("top")
local account = {566001,566002,566003,566004}
local accountId = {46,52,53,54}
local pin = {}
local accountbalance = {0,0,0,0}
function accountlogin() -- sets it so you can acces account functions
local senderId, message, distance = rednet.receive()
if message == "login" then
senderId, message, distance = rednet.receive()
for i,v in ipairs(account) do
  if message == v then
	accountnumb = message
	realaccount = true
	rednet.send(senderId, "accessing your account...", true)
	pins = (pin[i])
	accountsId = (accountID[i])
	rednet.send(senderId, pins, true)
  else
	rednet.send(senderId, "That account doesnt exist", true)  
  end
break
end
senderId, message, distance = rednet.receive()
  if message == "validuser" then
	accountaccess = true
  end
elseif message == "withdraw" then
  senderId, message, distance = rednet.receive()
  rednet.send(accountsId, message, true)
elseif message== "deposit" then
  senderId, message, distance = rednet.receive()
  rednet.send(accountsId, message, true)
elseif message == "create new account" then
  senderId, message, distance = rednet.receive()
  table.insert(pin, message)
  for i,v in ipairs(pin) do
	if message == v then
	local newaccount = (account[i])
	rednet.send(senderId, newaccount, true)
  end
end  
elseif message == "wire transfer" then
--wire transfer code
else
end
end
while true do
accountlogin()
end

Edited by xbsktball10x, 03 July 2013 - 11:50 PM.


#2 Tiin57

    Java Lunatic

  • Members
  • 1,412 posts
  • LocationIndiana, United States

Posted 30 June 2013 - 10:09 PM

Use [code], please.

#3 xbsktball10x

  • Members
  • 26 posts

Posted 30 June 2013 - 10:15 PM

got it there you go

#4 xbsktball10x

  • Members
  • 26 posts

Posted 03 July 2013 - 07:44 PM

bump.. really need some help with this

#5 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 04 July 2013 - 04:15 AM

Looking at your code it would probably be easy to have your accounts on a unique index, You could store the index as a number and increase it each time or use table.insert to insert the account array into the next available number.

That way each one of your accounts would be unique and will not clash.

account = {}

function newUser(pin, account)
  local u = {}
  u.pin = pin
  u.account = account
  return u
end

table.insert(account, newUser(2394994, 234))

-- in this example the new user will have an index of 1, so account[1].pin  would be there pin and
-- account[1].account would be their account number



Another thing, try using a function to save and load a database that way your accounts and balances wont be lost.
function saveDB(filename, theTable)
  theTable = textutils.serialize(theTable)
  local file = fs.open(filename, "w")
  file.write(theTable)
  file.close()
end
function loadDB(filename)
  file = fs.open(filename, "r")
  local content = file.readAll()
  file.close()
  return textutils.unserialize(content)
end

to use the second one just put tablename = loadDB(filename)
replacing tablename and filename respectively

(Might want to check my coding I quickly wrote it on a phone)

#6 TeamDman

  • Members
  • 13 posts
  • LocationCanada

Posted 05 July 2013 - 08:14 AM

Interesting idea for a banking system. Mind if I try to make a script like this?

#7 xbsktball10x

  • Members
  • 26 posts

Posted 05 July 2013 - 11:25 PM

Thank you so much guys this has been a frustrating process. and Team Dman go right ahead and write all you want im still working the bugs out with this one but if you come up with a script like this then please share it with me :D.

#8 xbsktball10x

  • Members
  • 26 posts

Posted 06 July 2013 - 02:03 AM

View Postdarkrising, on 04 July 2013 - 04:15 AM, said:

Looking at your code it would probably be easy to have your accounts on a unique index, You could store the index as a number and increase it each time or use table.insert to insert the account array into the next available number.

That way each one of your accounts would be unique and will not clash.

account = {}

function newUser(pin, account)
  local u = {}
  u.pin = pin
  u.account = account
  return u
end

table.insert(account, newUser(2394994, 234))

-- in this example the new user will have an index of 1, so account[1].pin  would be there pin and
-- account[1].account would be their account number


a little new to cc so how exactly would this work?

#9 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 06 July 2013 - 08:14 AM

View Postxbsktball10x, on 06 July 2013 - 02:03 AM, said:

View Postdarkrising, on 04 July 2013 - 04:15 AM, said:

-snip-
[/code]
a little new to cc so how exactly would this work?

Basically the function returns a new table with the data you have passed it, and then it is inserted into the next available index in the table.

For example:

function newUser(pin, account)
  local u = {}
  u.pin = pin
  u.account = account
  return u
end
aTable = newUser(123, 456)

--aTable.pin would equal 123
--aTable.account would equal 456

--So when we insert it into our main table
mainTable = {}

table.insert(mainTable, aTable)
--mainTable[1].pin would equal 123
--mainTable[1].account would equal 456

-- if we then did this again
table.insert(mainTable, newUser(111, 222)

--mainTable[2].pin would equal 111
--mainTable[2].account would equal 222


#10 TeamDman

  • Members
  • 13 posts
  • LocationCanada

Posted 06 July 2013 - 04:27 PM

Just trying to think of a way to make it 'impossible' to hack in...

#11 albrat

  • Members
  • 162 posts
  • LocationA Chair

Posted 06 July 2013 - 06:53 PM

basically I have this sort of system setup for my Server program for user logins. (except I do not allow account creation from users)
I wrote a system to input data into a table and read it back again accurately from a file / reference it against inputs...

local usrbase = {}
-- *************************
-- **  Functions listing  **
-- *************************

function newUser(user, pass) -- insert data
  local u = {}
  u[1] = user
  u[2] = pass
  return u
end

-- Save DataBase
function saveDB(filename, theTable)  -- call with saveDB (file, tablename)
  theTable = textutils.serialize(theTable)
  local file = fs.open(filename, "w")
  file.write(textutils.serialize(theTable))
  file.close()
end
-- append DataBase
function appDB(filename, theTable)  -- call with saveDB (file, tablename)
  theTable = textutils.serialize(theTable)
  local file = fs.open(filename, "a")
  file.write(textutils.serialize(theTable))
  file.close()
end
-- Load DataBase
function loadDB(filename)  --  Call with  tablename = loadDB(filename)
  file = fs.open(filename, "r")
  local content = file.readAll()
  file.close()
  return textutils.unserialize(content)
end

--[[ insert to tables. This is a one time run to insert my passwords
-- This is commented out in my actual program just add a - before the brackets to open the statement
print()
table.insert(usrbase, newUser("use1","pass3"))
print()
table.insert(usrbase, newUser("guest","pass1"))
table.insert(usrbase, newUser("user","pass2"))
saveDB("userbase", usrbase)
sleep(2)
error("data saved") -- end program so you can comment out the DB save
--]]
---[[ LoadDB  This loads the database into our system
usrbase = textutils.unserialize(loadDB("userbase"))
--]]

  for i= 1, #usrbase do
   if pas == usrbase[i][2] then  -- If the message matches a user password set our response to true
    valid = true 
    password = usrbase[i][2]
    break
   else
    valid = false  -- if no password matches...
   end
  end
  if valid then -- if we are valid respond the pass
   rednet.send(senderId, "valid", true)
  else
   rednet.send(senderId, "Not Valid", true)  -- otherwise respond Not Valid
  end
  end

I think I got all my code right in there...

basically this writes a table inside a table. It handles saving to a file and even works for retreiving the information back from the file. (which was difficult to achieve with some code setups)

to add more "fields" to your table just add another varible to the newUser() function and add a u[3] = {varible3name} into the code.

#12 xbsktball10x

  • Members
  • 26 posts

Posted 08 July 2013 - 02:26 AM

Dman what do you need to make impossible to hack into? the accounts? or like the gold storage area?

#13 TeamDman

  • Members
  • 13 posts
  • LocationCanada

Posted 08 July 2013 - 06:51 PM

If your sending signals between 2 computers for the banking what is to prevent someone from just copying a signal and sending that?

#14 bwhodle

  • Members
  • 14 posts
  • Locationstring expected, got nil

Posted 09 July 2013 - 04:50 PM

View PostTeamDman, on 08 July 2013 - 06:51 PM, said:

If your sending signals between 2 computers for the banking what is to prevent someone from just copying a signal and sending that?
Off topic but...
One thing you could do is use wired modems and then the hacker would actually have to literally walk all the way to the computer to get into the signal sending thing.
But since wired modems also have drawbacks you could use the Rednet api instead of the modem api, in which case you can check to see which computer is sending a message (its id) and see if it's a trusted id.
One md
11. 1. 3

#15 darkrising

  • Members
  • 234 posts
  • LocationScotland

Posted 10 July 2013 - 06:25 AM

View Postbwhodle, on 09 July 2013 - 04:50 PM, said:

View PostTeamDman, on 08 July 2013 - 06:51 PM, said:

If your sending signals between 2 computers for the banking what is to prevent someone from just copying a signal and sending that?
Off topic but...
One thing you could do is use wired modems and then the hacker would actually have to literally walk all the way to the computer to get into the signal sending thing.
But since wired modems also have drawbacks you could use the Rednet api instead of the modem api, in which case you can check to see which computer is sending a message (its id) and see if it's a trusted id.
One md
11. 1. 3

If you need to use rednet, just encrypt traffic between the computers, in my api I made encryption functions just for that purpose.

#16 Cutecurtain

  • Members
  • 31 posts
  • LocationBodafors, Sweden

Posted 10 July 2013 - 08:40 AM

I really like the idea with bank system :) Never seen it before,

#17 xbsktball10x

  • Members
  • 26 posts

Posted 10 July 2013 - 10:21 PM

Yeah Dman you would have to make a table of all the trusted computer Id's and make it run through the table and if it returns that its in there then allow access

#18 AgentE382

  • Members
  • 119 posts

Posted 10 July 2013 - 10:57 PM

View Postxbsktball10x, on 10 July 2013 - 10:21 PM, said:

Yeah Dman you would have to make a table of all the trusted computer Id's and make it run through the table and if it returns that its in there then allow access

Ahem... Why don't you just encrypt the traffic with my RC4 API ;)





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users