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

KREDITAPI: A complete banking API

Started by james222, 01 September 2014 - 02:52 PM
james222 #1
Posted 01 September 2014 - 04:52 PM
Introducing… KreditAPI!

What is the KreditAPI?
The KreditAPI is a complete banking api that includes many functions that helps you run a bank without having to manually enter data everytime. The KreditAPI does not include a gui, you will have to make your own gui until I make one.

Download
You can find the pastebin source here: Pastebin.com

Requirements
The KreditAPI requires 2 things:
The encryption class (Made by PixelToast)
A computer (It can be advanced or not, it doesn't matter. I recommend you install it on an advanced computer so you can build a fancy GUI)

Features
The Kredit API can do the following:
  • Save the user's bank account info
  • Save the user's transactions
  • List the user's transactions
  • Give money to another user
  • Change password (Admin function)
  • Delete Account
  • Give money (Admin function)
  • Remove money (Admin function)
  • List all accounts
  • More features comming soon!
How to use
The KreditAPI does not contain any GUI nor does it have a server software. I'll be working on a server software that can receive rednet requests.
  1. Place a computer
  2. Type the following: pastebin get s5aXm3Gs KREDITAPI
  3. Type the following: pastebin get WRTfH0yx enc
  4. Create your server software
  5. Use the following code to implement the API in your software: os.loadAPI("KREDITAPI")
  6. Use a function by typing KREDITAPI.[Function]([Arguments])

Functions
The KreditAPI has many functions that'll save you a lot of time. Here are the functions and a brief description (Listed in order they appear in the source code):
When a function returns false, that means it didn't do what the function should've done. It can be due to many things
  • applyDatabase() : Loads the database tables from the database variable (Database variable is filled when using loadDatabase())
  • Usage: applyDatabase()
  • saveDatabase() : Saves the database tables into a file. This function is automatically ran when using give()
  • Usage: savaDatabase()
  • loadDatabase() : Reads the database file from saveDatabase() and fills the database variable
  • Usage: loadDatabase()
  • listAccounts() : Lists all users registered. This can be used by anyone, so they can see all accounts and send money to the one he wants.
  • Usage: print(listAccounts())
  • createAccount(Username, Password) : Creates a new account.
  • Usage: createAccount("MyUserName", "MyPassword").
  • check(Username, Password) : Checks the user's balance. It requires password, because balance is something private that shouldn't be seen by everyone
  • Usage: print(check("MyUsername", "MyPassword"))
  • give(Username, Password, Amount, ReceiverName, EscapesFee) : Takes the money of the sender's account and gives it to the receiver. Escapes Fee is a boolean. If player escapes fee (due to x reason), no fee will be applied. See Variables section for more details
  • Usage: if give("MyUsername", "MyPassword", [MyAmount], "ThatGuy'sUsername") == true then print("Succesfully sent $ to X") end
  • checkCredentials(Username, Password) : Checks the username and password and makes sure that they match.
  • Usage: if checkCredentials("MyUsername", "MyPassword") == true then print("Valid info") end
  • checkUserExists(Username) : Checks if the specified username exists in the database
  • Usage: if checkUserExists("MyUsername") == true then print("Username exists") end
  • transac(amount) : Returns the amount of money that should be given after transaction fee is applied
  • Usage: if give("MyUsername", "MyPassword", transac([MyAmount]), "TheGuy'sName") == true then print("Transaction with fee sucessfull!") end
  • count() : Counts how many accounts there are in the database
  • Usage: print("There are " .. count() " accounts registered")
Admin Functions - Do not give access to these to a regular player
See variables section for more info on server password
  • setMoney(Username, Amount, ServerPassword) : Sets the user's balance to the specified amount.
  • Usage: if setMoney("MyUsername", 100, "MyServerPassword") == true then print("Succesfully set the user's money to X") end
  • listMoney(ServerPassword) : Returns all the money of the users in a list
  • Usage: print(listMoney("MyServerPassword"))
  • showMoney(Username, ServerPassword) : Shows the money of a specific user
  • Usage: print(showMoney("MyUsername", "MyServerPassword"))
  • addMoney(Username, Amount, ServerPassword) : Adds the specified amount of money to the specified username
  • Usage: if addMoney("MyUsername", [MyAmount], "MyServerPassword") == true then print("Succesfully added X $ to X") end
  • removeMoney(Username, Amount, ServerPassword) : Removes the specified amount of money from the specified username. Amount does not need to be negative.
  • Usage: if removeMoney("MyUsername", [MyAmount], "MyServerPassword") == true then print("Succesfully removed X $ from X") end
  • deleteAccount(Username, ServerPassword) : Deletes the specified account
  • Usage: if deleteAccount("MyUsername", "MyServerPassword") == true then print("Succesfully deleted account") end
  • showInTransaction(Username, ServerPassword) : Shows the money that came into the user's account
  • Usage: print(showInTransaction("MyUsername", "MyServerPassword"))
  • showOutTransaction(Username, ServerPassword) :Shows the money that came out of the user's account
  • Usage: print(showOutTransaction("MyUsername", "MyServerPassword"))
  • setPassword(Username, NewPassword, ServerPassword) : Sets the user's password to the specified password
  • Usage: if setPassword("MyUsername", "MyNewPassword", "MyServerPassword") == true then print("Succesfully set new password") end
Variables
These are the variables that you are allowed to modify
  • transactionFee : It is the percentage of $ taken from a transaction. It is used in the transac() function
  • Example: transactionFee = 10. That means there will be a 10% transaction fee
  • serverAdminPassword : It is the password required when using admin commands. Change it before using the API
  • Example: serverAdminPassword = "Blob".
  • encryptionPassword : It is the password used to encrypt & decrypt passwords Change it before using the API
  • Example: encryptionPassword = "Blob222"
  • autoRead : Defines if the accounts file should automatically loaded once the script is ran
  • Example: autoRead = true
Credit/License:
You may use the KREDITAPI in your programs. If you are to make a video about it, give me the credit for the API. Thanks to Pixel Toast for the encryption API

To Do List:
  1. Create a server software
  2. Create a registration software that isn't in the main server (For security reasons) (The command will travel throught rednet network)
  3. Create atm software
  4. Create client software
Bugs:
If there are any bugs, please tell me what code you wrote, and what the error was.
If there is a bug that isn't related to an error in the code, make sure that:
  1. You used the good function
  2. You used saveDatabase() function after
If you tried these steps and it still doesn't work, leave a reply and I'll see what I can do.


This is my first officially released program in LUA. There may be bugs. Have fun using it!
Edited on 02 September 2014 - 09:34 PM
FUNCTION MAN! #2
Posted 02 September 2014 - 01:46 AM
LUA? Lua*. Lua is a word, in portuguese, that means moon. You writing LUA like that, is the same thing as an american writing TABLE, or maybe DESK.

Back on-topic :

I really don't see the point of money apis, when, in Lua, there is no security for functions. If there were such things as private, banking apis would be possible, but, still useless.
This is one of the most complete ones I've seen, even at this early state.
Cranium #3
Posted 02 September 2014 - 08:30 AM
LUA? Lua*. Lua is a word, in portuguese, that means moon. You writing LUA like that, is the same thing as an american writing TABLE, or maybe DESK.
Don't nitpick. Nobody likes a smart-alek.
james222 #4
Posted 02 September 2014 - 11:33 PM
LUA? Lua*. Lua is a word, in portuguese, that means moon. You writing LUA like that, is the same thing as an american writing TABLE, or maybe DESK.
Don't nitpick. Nobody likes a smart-alek.

He's probably just a troll.
LUA? Lua*. Lua is a word, in portuguese, that means moon. You writing LUA like that, is the same thing as an american writing TABLE, or maybe DESK.

Back on-topic :

I really don't see the point of money apis, when, in Lua, there is no security for functions. If there were such things as private, banking apis would be possible, but, still useless.
This is one of the most complete ones I've seen, even at this early state.

Well it is safe. As long as you don't give access to the main server, no one will be able to hack it unless they hack the server or find a way to crack the enryption used when communicating from the client to the server.
DangerAngel97 #5
Posted 16 May 2015 - 11:49 PM
Can you please look into the encrytion program. It keeps on giving me an error on decrypting.

Error line 154: "attempt to get length of nil"

If you could be so kind to fix this I would really appreciate it.