Spaces:
Sleeping
Sleeping
File size: 5,280 Bytes
1766c2e 5e13bae 1766c2e 4b12db0 1766c2e 4b12db0 5e13bae 1766c2e 823ac27 1766c2e 823ac27 12a3a3f 1766c2e 12a3a3f 1766c2e 823ac27 1766c2e 4b12db0 d755156 4b12db0 1766c2e 823ac27 1766c2e 4b12db0 1766c2e 823ac27 4b12db0 1766c2e 8374200 1766c2e 823ac27 4b12db0 1766c2e 823ac27 1766c2e 5e13bae 1766c2e | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | import streamlit as st
import random
import os
import smtplib
from email.message import EmailMessage
import json
# ---------- UTILITY FUNCTIONS ----------
def load_data():
try:
with open('accounts.json', 'r') as f:
return json.load(f)
except:
return {}
def save_data(data):
with open('accounts.json', 'w') as f:
json.dump(data, f, indent=4)
def send_otp(email):
otp = str(random.randint(1000, 9999))
st.session_state['otp'] = otp
sender_email = os.environ['EMAIL_USER']
sender_password = os.environ['EMAIL_PASS']
msg = EmailMessage()
msg['Subject'] = "Your Baryashah Bank OTP"
msg['From'] = sender_email
msg['To'] = email
msg.set_content(f"Your OTP for Baryashah Bank is: {otp}")
with smtplib.SMTP_SSL('smtp.gmail.com', 465) as smtp:
smtp.login(sender_email, sender_password)
smtp.send_message(msg)
st.info(f"β
OTP sent to {email}")
return otp
def verify_otp(user_input):
return user_input == st.session_state.get('otp')
# ---------- APP UI ----------
st.title("π Baryashah Bank Pro Dashboard π")
st.write("Professional banking simulation. Login, withdraw, deposit & reset password securely.")
data = load_data()
menu = ["Create Account", "Login", "Reset Password"]
choice = st.sidebar.selectbox("Menu", menu)
# ---------- CREATE ACCOUNT ----------
if choice == "Create Account":
st.header("π Create New Account")
name = st.text_input("Full Name")
email = st.text_input("Email")
age = st.number_input("Age", min_value=1, max_value=120)
password = st.text_input("Create Password", type="password")
if st.button("Create Account"):
if age < 18:
st.error("β Must be 18 or older to create an account.")
elif email in data:
st.error("β Account with this email already exists.")
else:
data[email] = {
"name": name,
"age": age,
"password": password,
"balance": 0,
"transactions": []
}
save_data(data)
st.success(f"β
Account created for {name}!")
# ---------- LOGIN ----------
elif choice == "Login":
st.header("π Login")
email = st.text_input("Email")
password = st.text_input("Password", type="password")
if st.button("Send OTP"):
if email not in data:
st.error("β Email not registered!")
elif data[email]["password"] != password:
st.error("β Wrong password!")
else:
send_otp(email)
otp_input = st.text_input("Enter OTP")
if st.button("Verify OTP"):
if verify_otp(otp_input):
st.success(f"β
Welcome {data[email]['name']}!")
# Dashboard
st.subheader("π° Account Dashboard")
st.metric("Balance", f"${data[email]['balance']}")
col1, col2 = st.columns(2)
with col1:
deposit_amount = st.number_input("Deposit Amount", min_value=1)
if st.button("Deposit"):
data[email]['balance'] += deposit_amount
data[email]['transactions'].append(f"Deposit: +${deposit_amount}")
save_data(data)
st.success(f"β
Deposited ${deposit_amount} successfully!")
with col2:
withdraw_amount = st.number_input("Withdraw Amount", min_value=1)
if st.button("Withdraw"):
# Send OTP before withdrawal
send_otp(email)
otp_withdraw = st.text_input("Enter OTP to withdraw")
if st.button("Confirm Withdrawal"):
if verify_otp(otp_withdraw):
if withdraw_amount <= data[email]['balance']:
data[email]['balance'] -= withdraw_amount
data[email]['transactions'].append(f"Withdraw: -${withdraw_amount}")
save_data(data)
st.success(f"β
Withdrawn ${withdraw_amount} successfully!")
else:
st.error("β Insufficient Balance!")
else:
st.error("β Wrong OTP!")
# Show transactions
st.subheader("π Transaction History")
for t in data[email]['transactions']:
st.write(t)
else:
st.error("β OTP incorrect!")
# ---------- PASSWORD RESET ----------
elif choice == "Reset Password":
st.header("π Reset Password")
email = st.text_input("Registered Email")
if st.button("Send OTP for Reset"):
if email not in data:
st.error("β Email not registered!")
else:
send_otp(email)
otp_input = st.text_input("Enter OTP received")
new_pass = st.text_input("Enter New Password", type="password")
if st.button("Reset Password"):
if verify_otp(otp_input):
data[email]['password'] = new_pass
save_data(data)
st.success("β
Password reset successfully!")
else:
st.error("β OTP incorrect!") |