Front page
Acknowledgement
certificate
Intriduction of project
Source Code
import mysql.connector
# Connect to MySQL database
def connect_to_db():
return mysql.connector.connect(
host="localhost",
user="root",
password="12345",
database="atm_system"
# Function to authenticate user based on account number and PIN
def authenticate_user(account_number, pin):
db = connect_to_db()
cursor = db.cursor()
query = "SELECT * FROM users WHERE account_number = %s AND pin = %s"
cursor.execute(query, (account_number, pin))
user = cursor.fetchone()
db.close()
if user:
return user # return user details (account_number, pin, balance)
else:
return None
# Function to check balance
def check_balance(account_number):
db = connect_to_db()
cursor = db.cursor()
query = "SELECT balance FROM users WHERE account_number = %s"
cursor.execute(query, (account_number,))
balance = cursor.fetchone()
db.close()
if balance:
return balance[0]
else:
return None
# Function to deposit money
def deposit(account_number, amount):
db = connect_to_db()
cursor = db.cursor()
query = "UPDATE users SET balance = balance + %s WHERE account_number = %s"
cursor.execute(query, (amount, account_number))
db.commit()
db.close()
# Function to withdraw money
def withdraw(account_number, amount):
db = connect_to_db()
cursor = db.cursor()
# Check current balance
current_balance = check_balance(account_number)
if current_balance is None:
return "Account not found!"
if amount > current_balance:
return "Insufficient funds!"
# Update the balance after withdrawal
query = "UPDATE users SET balance = balance - %s WHERE account_number = %s"
cursor.execute(query, (amount, account_number))
db.commit()
db.close()
return "Withdrawal successful!"
# Main ATM system interface
def atm_system():
print("Welcome to the ATM System!")
# Get account number and PIN from the user
account_number = int(input("Enter your account number: "))
pin = input("Enter your PIN: ")
# Authenticate the user
user = authenticate_user(account_number, pin)
if user:
print(f"Welcome {account_number}!")
while True:
print("\nATM Menu:")
print("1. Check Balance")
print("2. Deposit Money")
print("3. Withdraw Money")
print("4. Exit")
choice = int(input("Enter your choice: "))
if choice == 1:
balance = check_balance(account_number)
print(f"Your current balance is: {balance}")
elif choice == 2:
amount = float(input("Enter amount to deposit: "))
deposit(account_number, amount)
print(f"{amount} has been deposited to your account.")
elif choice == 3:
amount = float(input("Enter amount to withdraw: "))
result = withdraw(account_number, amount)
print(result)
elif choice == 4:
print("Thank you for using the ATM system. Goodbye!")
break
else:
print("Invalid choice. Please try again.")
else:
print("Invalid account number or PIN. Please try again.")
# Run the ATM system
if __name__ == "__main__":
atm_system()
Output
Main Screen
Account Menu
Check balance
Deposit Money
Withdraw Money
Exit
Mysql Database and Tables used in this project
Structure of table
Insert the record
Display the Record