A simple command-line interface (CLI) banking application written in Python.
- User registration and login
- Deposit, withdraw, and transfer funds between current and savings accounts
- View transaction history
- Secure password hashing with bcrypt
- Configuration via environment variables
-
Clone the repository:
git clone https://github.com/H41L33/t_level_dsd_river_bank_system cd river_bank_system -
Install Poetry: If you don't have Poetry installed, follow the instructions on the official Poetry website.
-
Install dependencies: Poetry will create a virtual environment automatically and install the dependencies listed in the
pyproject.tomlfile.poetry install
-
Configure environment variables:
- Copy the
.env.examplefile to.env:cp .env.example .env
- Edit the
.envfile with your desired settings.
- Copy the
Run the main application using Poetry's run command. This ensures the script executes within the correct virtual environment managed by Poetry.
poetry run python -m river_bank_system.mainThe application is designed to be a loop, continuously prompting the user for input until they choose to exit. Here’s a breakdown of how data moves through the system with the new structure.
- The program starts by running
main.py. - The
main()function immediately callsmenus.program_start(), which clears the screen and displays the first choice: Login, Register, or Quit.
- If you choose to register, you'll be guided by the
create_user_prompt()function inmenus.py. - This function collects your desired
username,display_name, andpassword. - Your password is then sent to
crypto.hash_bcrypt()to be securely hashed. - Finally, this information is passed to
users.UsersDB().create_new_user(), which inserts a new record into thetbl_accountstable in your SQLite database.
- If you opt to log in, the
login_prompt()function inmenus.pywill ask for yourusernameandpassword. - The
usernameis used to fetch the stored password hash from the database viausers.UsersDB().get_password_hash(). - The plain-text password you entered and the stored hash are then passed to
auth.check_password()to see if they match.bcrypthandles this comparison securely without ever exposing the original password.
-
Once logged in, the
home_page()function inmain.pytakes over. -
It uses
menus.account_dashboard()to display your account balances and the available actions: Deposit, Withdraw, Transfer, View Transactions, and Logout. Your balance information is fetched from the database using functions within theusers.UsersDBclass. -
When you select a financial action (like Deposit),
main.pycreates anactions.Actions(username)object. This object manages the two-step process for every transaction:- Update Balance: The
Actionsclass first calls a method from theusers.UsersDBclass (e.g.,add_current_balance) to update your balance in thetbl_accountstable. - Log Transaction: Immediately after, it calls
transactions.TransactionsDB().log_transaction()to create a permanent record of the event in thetbl_transactionstable.
- Update Balance: The
-
If you choose to view your history,
main.pycallstransactions.TransactionsDB().get_transactions()to retrieve and display the recent records.
To enhance the functionality and security of this command-line application, a few key external libraries were chosen:
-
Click: This library is used to create a more user-friendly and robust command-line interface (CLI). Instead of using Python's built-in
input(), Click provides functions for styled output (like colors), clearing the screen, and creating clean, validated prompts. This improves the overall user experience when interacting with the bank system in the terminal. -
Bcrypt: Security is paramount when dealing with user credentials. The
bcryptlibrary is a trusted and secure way to handle password hashing. When a user creates a password, it is not stored in plain text. Instead, it is run through a hashing algorithm to create a unique, fixed-length "hash." When the user logs in, the password they enter is hashed again and compared to the stored hash. This ensures that even if the database were compromised, the actual passwords would remain protected.