Computer science project on(ali) - Copy
Computer science project on(ali) - Copy
Introduction
In today’s digital age, online banking has become an essential service
for managing finances efficiently. This project aims to develop an
online banking portal that allows users to perform various banking
operations securely and conveniently. By leveraging Python for
backend development and SQL for database management, the portal
will provide functionalities such as user registration, account
management, fund transfers, and transaction history tracking.
Objectives
1. User Authentication: Implement a secure login and registration
system to protect user data.
2. Account Management: Allow users to view and update their
account information.
3. Fund Transfers: Enable users to transfer funds between
accounts with real-time updates.
4. Transaction History: Provide users with a detailed view of their
past transactions.
5. Data Security: Ensure the integrity and confidentiality of user
data through encryption and secure coding practices.
Technologies Used
Python: Used for the backend development, handling user
requests and database interactions.
SQL: Used for managing the database, storing user information,
account details, and transaction records.
def init_db():
with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
cursor.execute('''
CREATE TABLE IF NOT EXISTS users (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL UNIQUE,
password TEXT NOT NULL
)
''')
cursor.execute('''
CREATE TABLE IF NOT EXISTS accounts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
user_id INTEGER,
balance REAL DEFAULT 0,
FOREIGN KEY (user_id) REFERENCES users (id)
)
''')
conn.commit()
2. User Registration and Login
register Function: Takes a username and password, then inserts them into the users
table. It handles unique usernames by catching sqlite3.IntegrityError.
def register(username, password):
with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
try:
cursor.execute('INSERT INTO users (username, password) VALUES (?, ?)', (username,
password))
conn.commit()
print("Registration successful!")
except sqlite3.IntegrityError:
print("Username already exists.")
Login Function: Validates user credentials by checking if they exist in the users
table. If the user is found, it returns the user’s data.
def check_balance(user_id):
with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
cursor.execute('SELECT balance FROM accounts WHERE user_id=?',
(user_id,))
balance = cursor.fetchone()
return balance[0] if balance else 0
Deposit and withdraw Functions: Modify the account balance based on the
amount provided. They ensure sufficient funds are available for withdrawals.
def main():
init_db()
while True:
print("\n1. Register\n2. Login\n3. Exit")
choice = input("Choose an option: ")
if choice == '1':
username = input("Enter username: ")
password = input("Enter password: ")
register(username, password)
elif choice == '2':
username = input("Enter username: ")
password = input("Enter password: ")
user = login(username, password)
if user:
user_id = user[0]
print(f"Welcome, {username}!")
while True:
print("\n1. Create Account\n2. Check Balance\n3. Deposit\n4.
Withdraw\n5. Logout")
option = input("Choose an option: ")
if option == '1':
create_account(user_id)
2. User Registration
User chooses to register:
yaml
Copy code
Choose an option: 1
Enter username: madhav
Enter password: securepassword
Registration successful!
3. Logging In
User chooses to log in:
markdown
Copy code
1. Register
2. Login
3. Exit
Choose an option: 2
Enter username: madhav
Enter password: securepassword
Welcome, madhav!
4. Account Management
User creates an account:
markdown
Copy code
1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 1
Account created successfully!
5. Logging Out
1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 5
Logged out.
Summary
The code initializes a database and allows users to register and log in.
Users can create accounts, check balances, deposit, and withdraw money.
It uses a simple console interface for interaction, making it easy to test
and extend.
Bibliography
Sumitha aroura class 12
Real Python. “Python and SQLite: A Simple Guide.” Real Python. Accessed
October 2023.
Tutorialspoint. “Python SQLite.” Tutorialspoint. Accessed October 2023.