0% found this document useful (0 votes)
6 views

Computer science project on(ali) - Copy

Uploaded by

madhavramesh9e08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Computer science project on(ali) - Copy

Uploaded by

madhavramesh9e08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Computer science project on -

Bank online portal


By – Madhav Ramesh

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.

Code Structure Overview


1. Database Initialization
2. User Registration and Login
3. Account Management
4. Main Application Loop
1. Database Initialization (init_db)
This function sets up the SQLite database and creates the necessary
tables:
 users Table: Stores user information (id, username, password).
 accounts Table: Stores account information (id, user_id,
balance).

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 login(username, password):


with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
cursor.execute('SELECT * FROM users WHERE username=? AND
password=?', (username, password))
return cursor.fetchone()

3. Account Management Functions


 create_account Function: Creates a new account linked to the logged-in
user.
def create_account(user_id):
with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
cursor.execute('INSERT INTO accounts (user_id) VALUES (?)', (user_id,))
conn.commit()
print("Account created successfully!")

check_balance Function: Retrieves the balance of the user's account.

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 deposit(user_id, amount):


with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
cursor.execute('UPDATE accounts SET balance = balance + ? WHERE
user_id=?', (amount, user_id))
conn.commit()
print("Deposit successful!")
def withdraw(user_id, amount):
with sqlite3.connect('bank.db') as conn:
cursor = conn.cursor()
balance = check_balance(user_id)
if amount <= balance:
cursor.execute('UPDATE accounts SET balance = balance - ? WHERE
user_id=?', (amount, user_id))
conn.commit()
print("Withdrawal successful!")
else:
print("Insufficient balance.")

4. Main Application Loop


The main function handles the application flow, allowing users to register, log
in, and manage their accounts:

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)

elif option == '2':


balance = check_balance(user_id)
print(f"Your balance is: ${balance}")

elif option == '3':


amount = float(input("Enter deposit amount: "))
deposit(user_id, amount)

elif option == '4':


amount = float(input("Enter withdrawal amount: "))
withdraw(user_id, amount)

elif option == '5':


print("Logged out.")
break
else:
print("Invalid username or password.")

elif choice == '3':


print("Goodbye!")
break
sample Output

1. Starting the Application


markdown
Copy code
1. Register
2. Login
3. Exit
Choose an option:

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!

User checks balance:


markdown
Copy code
1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 2
Your balance is: $0
User deposits money:
1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 3
Enter deposit amount: 100
Deposit successful!

User checks balance again:


1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 2
Your balance is: $100

User withdraws money:


1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 4
Enter withdrawal amount: 50
Withdrawal successful!

User checks balance again:


1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 2
Your balance is: $50

5. Logging Out
1. Create Account
2. Check Balance
3. Deposit
4. Withdraw
5. Logout
Choose an option: 5
Logged out.

6. Exiting the Application


1. Register
2. Login
3. Exit
Choose an option: 3
Goodbye!
Explanation of Output
 The user begins by choosing to register or log in.
 After registering, the user can log in with the provided credentials.
 Once logged in, the user can manage their account by creating accounts,
checking balances, depositing, and withdrawing funds.
 The output messages guide the user through each action, providing
feedback on successes or errors (e.g., insufficient funds).
 Finally, the user can log out or exit the application.

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.

You might also like