krishbaresha commited on
Commit
8374200
·
verified ·
1 Parent(s): 4b12db0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -5
app.py CHANGED
@@ -27,7 +27,7 @@ def send_otp():
27
  return str(random.randint(1000,9999))
28
 
29
  # --- User Options ---
30
- menu = ["Create Account", "Login / Check Balance", "Reset Password"]
31
  choice = st.sidebar.selectbox("Menu", menu)
32
 
33
  accounts = load_accounts()
@@ -38,14 +38,18 @@ if choice == "Create Account":
38
  name = st.text_input("Full Name")
39
  age = st.number_input("Age", min_value=1, max_value=120)
40
  password = st.text_input("Create Password", type="password")
 
41
  if st.button("Create Account", key="create"):
42
  if name in accounts:
43
  st.error("Account already exists!")
 
 
44
  else:
45
  acc_no = random.randint(1000,9999)
46
  accounts[name] = {
47
  "age": age,
48
  "password": password,
 
49
  "account_number": acc_no,
50
  "balance": 0,
51
  "transactions": []
@@ -73,6 +77,17 @@ elif choice == "Reset Password":
73
  else:
74
  st.error("Invalid OTP!")
75
 
 
 
 
 
 
 
 
 
 
 
 
76
  # --- Login / Check Balance ---
77
  elif choice == "Login / Check Balance":
78
  st.subheader("Login")
@@ -88,15 +103,18 @@ elif choice == "Login / Check Balance":
88
  col1, col2 = st.columns(2)
89
  with col1:
90
  withdraw_amt = st.number_input("Withdraw Amount", min_value=0)
 
91
  if st.button("Withdraw", key="withdraw"):
92
- if withdraw_amt <= accounts[name]['balance']:
 
 
 
 
93
  accounts[name]['balance'] -= withdraw_amt
94
  accounts[name]['transactions'].append({"type":"Withdraw", "amount":withdraw_amt})
95
  save_accounts(accounts)
96
  st.success(f"💸 Withdraw Successful! New Balance: {accounts[name]['balance']}")
97
  st.balloons()
98
- else:
99
- st.error("Insufficient Balance!")
100
 
101
  with col2:
102
  deposit_amt = st.number_input("Deposit Amount", min_value=0)
@@ -115,4 +133,4 @@ elif choice == "Login / Check Balance":
115
  fig = px.bar(x=list(range(1,len(amounts)+1)), y=amounts, color=types, labels={'x':'Transaction','y':'Amount'}, title="Transaction History")
116
  st.plotly_chart(fig)
117
  else:
118
- st.error("Login failed! Check credentials.")
 
27
  return str(random.randint(1000,9999))
28
 
29
  # --- User Options ---
30
+ menu = ["Create Account", "Login / Check Balance", "Reset Password", "Recover Account Number"]
31
  choice = st.sidebar.selectbox("Menu", menu)
32
 
33
  accounts = load_accounts()
 
38
  name = st.text_input("Full Name")
39
  age = st.number_input("Age", min_value=1, max_value=120)
40
  password = st.text_input("Create Password", type="password")
41
+ pin = st.text_input("Create 4-digit PIN (for withdrawals)", type="password", max_chars=4)
42
  if st.button("Create Account", key="create"):
43
  if name in accounts:
44
  st.error("Account already exists!")
45
+ elif len(pin)!=4 or not pin.isdigit():
46
+ st.error("PIN must be 4 digits")
47
  else:
48
  acc_no = random.randint(1000,9999)
49
  accounts[name] = {
50
  "age": age,
51
  "password": password,
52
+ "pin": pin,
53
  "account_number": acc_no,
54
  "balance": 0,
55
  "transactions": []
 
77
  else:
78
  st.error("Invalid OTP!")
79
 
80
+ # --- Account Number Recovery ---
81
+ elif choice == "Recover Account Number":
82
+ st.subheader("Recover Account Number")
83
+ name = st.text_input("Enter Account Name")
84
+ password = st.text_input("Enter Password", type="password")
85
+ if st.button("Recover Account Number"):
86
+ if name in accounts and accounts[name]['password'] == password:
87
+ st.success(f"Your Account Number is: {accounts[name]['account_number']}")
88
+ else:
89
+ st.error("Invalid credentials!")
90
+
91
  # --- Login / Check Balance ---
92
  elif choice == "Login / Check Balance":
93
  st.subheader("Login")
 
103
  col1, col2 = st.columns(2)
104
  with col1:
105
  withdraw_amt = st.number_input("Withdraw Amount", min_value=0)
106
+ user_pin = st.text_input("Enter PIN for Withdrawal", type="password")
107
  if st.button("Withdraw", key="withdraw"):
108
+ if user_pin != accounts[name]['pin']:
109
+ st.error("Incorrect PIN! Withdrawal denied.")
110
+ elif withdraw_amt > accounts[name]['balance']:
111
+ st.error("Insufficient Balance!")
112
+ else:
113
  accounts[name]['balance'] -= withdraw_amt
114
  accounts[name]['transactions'].append({"type":"Withdraw", "amount":withdraw_amt})
115
  save_accounts(accounts)
116
  st.success(f"💸 Withdraw Successful! New Balance: {accounts[name]['balance']}")
117
  st.balloons()
 
 
118
 
119
  with col2:
120
  deposit_amt = st.number_input("Deposit Amount", min_value=0)
 
133
  fig = px.bar(x=list(range(1,len(amounts)+1)), y=amounts, color=types, labels={'x':'Transaction','y':'Amount'}, title="Transaction History")
134
  st.plotly_chart(fig)
135
  else:
136
+ st.error("Login failed! Check credentials.")