-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathABC_CoreBankingSystem.py
534 lines (494 loc) · 19 KB
/
ABC_CoreBankingSystem.py
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
import mysql.connector as spc
co = spc.connect(host='localhost', user='toor', passwd='')
# Creating a Bank Account
def CreateAccount():
# OTP Password = nsiruyegnabfpawh
cu = co.cursor()
# cu.execute("create database ABC_CBS;")
cu.execute("use ABC_CBS;")
# cu.execute("create table user_details(Aadhar bigint primary key, Mobile_No bigint, GMail_ID varchar(50), Password varchar(50), Name varchar(50), DateOfBirth date, Balance float default 0.0);")
loop = True
while loop:
print()
choice_2 = input("Would you like to create an Account? (Yes/No): ")
print()
if choice_2 == "Yes" or choice_2 == "yes":
user_aadhar = int(input("Please enter your Aadhar Number (Must be 12-Digits): "))
user_mobile_no = int(input("Please enter your Mobile Number (Must be 10-Digits): "))
user_gmail_id = input("Please enter your G-Mail ID: ")
try:
while True:
if OTPVerification(user_gmail_id):
print('OTP verified successfully.')
print()
break
else:
print("OTP failed to verify. Please try again.")
continue
except:
print()
print("Invalid G-Mail ID. Please try again.")
continue
while True:
user_passwd = input("Please enter a Strong Password: ")
user_passwd_r = input("Please re-enter your Password: ")
print()
if user_passwd == user_passwd_r:
break
else:
print("Passwords don't match. Please try again.")
print()
continue
user_name = input("Please enter your Name: ")
user_dob = input("Please enter your Date of Birth (YYYY-MM-DD): ")
query = "insert into user_details values(%s, %s, '%s', '%s', '%s', '%s', 0.0)" % (user_aadhar, user_mobile_no, user_gmail_id, user_passwd, user_name, user_dob)
cu.execute(query)
print()
print("Account created!")
loop2 = True
while loop2:
print()
choice_3 = input("Would you like to create another account? (Yes/No): ")
if choice_3 == "Yes" or choice_3 == "yes":
break
elif choice_3 == "No" or choice_3 == "no":
loop = False
loop2 = False
print()
else:
print()
print("Invalid choice. Please enter your choice again.")
continue
elif choice_2 == "No" or choice_2 == "no":
break
else:
print("Invalid choice. Please enter your choice again.")
co.commit()
# Logging into an Account
def LoginAccount():
cu = co.cursor()
cu.execute("use ABC_CBS;")
loop = True
global logged_in
logged_in = False
while loop:
cu.execute("select * from user_details;")
data = cu.fetchall()
count = 0
print()
temp_g = input("Please enter your G-Mail ID: ")
temp_p = input("Please enter your password: ")
for i in range(len(data)):
if temp_g == data[i][2]:
count = count + 1
for i in range(len(data)):
if count == 1:
if temp_g == data[i][2] and temp_p == data[i][3]:
loop4 = True
while loop4:
if OTPVerification(temp_g):
print('OTP verified successfully.')
print()
print("Successfully logged in! Welcome back,", data[i][4])
logged_in = True
loop4 = False
else:
print("OTP failed to verify. Please try again.")
continue
break
elif count == 0:
print()
print("No Accounts found. Please try again.")
break
elif count > 1 and temp_g == data[i][2] and temp_p == data[i][3]:
print()
print("Accounts with the same email has been found. Please enter your Aadhar Number to continue.")
loop2 = True
while loop2:
print()
temp_a = int(input("Please enter your Aadhar Number: "))
for i in range(len(data)):
if temp_g == data[i][2] and temp_p == data[i][3] and temp_a == data[i][0]:
print()
print("Successfully logged in! Welcome back,", data[i][4])
logged_in = True
loop2 = False
break
else:
print()
print("Invalid Aadhar. Please try again.")
loop2 = False
continue
break
else:
print()
print("Wrong G-Mail/Password. Please try again.")
logged_in = False
try:
if temp_a:
pass
except:
temp_a = None
if logged_in:
ManageAccount(temp_g, temp_a)
print()
loop3 = True
while loop3:
choice_2 = input("Do you wish to login to another account? (Yes/No): ")
if choice_2 == 'Yes' or choice_2 == 'yes':
loop3 = False
loop = True
logged_in = False
continue
elif choice_2 == 'No' or choice_2 == 'no':
loop = False
print()
break
else:
print("Invalid choice. Please try again.")
print()
continue
co.commit()
# Changing the Customer's G-Mail ID
def ChangeMobile(t_go):
cu = co.cursor()
cu.execute("use ABC_CBS;")
i = 0
loop = True
new_mobile = None
while loop:
cu.execute("select * from user_details")
data = cu.fetchall()
print()
t_a = int(input("Please enter your Aadhar Number: "))
t_m = input("Please enter your new Mobile Number: ")
while i < len(data):
if t_a == data[i][0] and t_go == data[i][2]:
query = "update user_details set Mobile_No = '%s' where Aadhar = %s" % (t_m, t_a)
cu.execute(query)
loop = False
new_mobile = True
break
i = i + 1
else:
loop2 = True
while loop2:
choice_2 = input("Mobile Number not updated. Would you like to try again? (Yes/No): ")
if choice_2 == "Yes" or choice_2 == "yes":
break
elif choice_2 == "No" or choice_2 == "no":
loop = False
break
else:
print("Invalid choice. Please try again.")
if new_mobile:
print()
print("Mobile Number changed successfully.")
co.commit()
# Changing the Customer's G-Mail ID
def ChangeGMail(t_go):
cu = co.cursor()
cu.execute("use ABC_CBS;")
i = 0
loop = True
new_mail = None
while loop:
cu.execute("select * from user_details")
data = cu.fetchall()
print()
t_a = int(input("Please enter your Aadhar Number: "))
t_g = input("Please enter your new G-Mail ID: ")
while True:
if OTPVerification(t_g):
print('OTP verified successfully.')
print()
break
else:
print("OTP failed to verify. Please try again.")
print()
continue
while i < len(data):
if t_a == data[i][0] and t_go == data[i][2]:
query = "update user_details set GMail_ID = '%s' where Aadhar = %s" % (t_g, t_a)
cu.execute(query)
loop = False
new_mail = True
break
i = i + 1
else:
loop2 = True
while loop2:
choice_2 = input("G-Mail not updated. Would you like to try again? (Yes/No): ")
if choice_2 == "Yes" or choice_2 == "yes":
break
elif choice_2 == "No" or choice_2 == "no":
loop = False
break
else:
print("Invalid choice. Please try again.")
if new_mail:
print("G-Mail changed successfully.")
co.commit()
# Changing the Customer's Password
def ChangePassword():
cu = co.cursor()
cu.execute("use ABC_CBS;")
loop = True
while loop:
cu.execute("select * from user_details;")
data = cu.fetchall()
print()
print("1. Change Password via G-Mail")
print("2. Change Password via Aadhar Verification")
print("3. Exit")
print()
choice_2 = int(input("Please enter your choice: "))
print()
if choice_2 == 1:
temp_g = input("Please enter your G-Mail ID: ")
otp_v = False
while True:
try:
if OTPVerification(temp_g):
print('OTP verified successfully.')
print()
otp_v = True
break
except:
print("OTP failed to verify. Please try again.")
print()
continue
while True:
new_p = input("Please enter a Strong Password: ")
new_pr = input("Please re-enter your Password: ")
if new_p == new_pr:
break
else:
print()
print("Passwords don't match. Please try again.")
print()
continue
count = 0
for i in range(len(data)):
if temp_g == data[i][2]:
count = count + 1
for i in range(len(data)):
if count == 1 and otp_v:
query = "update user_details set Password = '%s' where GMail_ID = '%s';" % (new_p, temp_g)
cu.execute(query)
print()
print("Password changed successfully.")
loop = False
break
elif count > 1:
print()
print("More than 2 Accounts with same G-Mail has been found.")
temp_a = int(input("Please enter your Aadhar Number: "))
for i in range(len(data)):
if temp_g == data[i][2] and temp_a == data[i][0]:
query = "update user_details set Password = '%s' where GMail_ID = '%s' and Aadhar = '%s';" % (new_p, temp_g, temp_a)
cu.execute(query)
print()
print("Password changed successfully.")
loop = False
break
else:
print('Invalid G-Mail ID/Aadhar. Please try again.')
print()
break
elif choice_2 == 2:
temp_g = input("Please enter your G-Mail ID: ")
temp_a = int(input("Please enter your Aadhar Number: "))
while True:
new_p = input("Please enter a Strong Password: ")
new_pr = input("Please re-enter your Password: ")
if new_p == new_pr:
break
else:
print()
print("Passwords don't match. Please try again.")
print()
continue
for i in range(len(data)):
if temp_g == data[i][2] and temp_a == data[i][0]:
query = "update user_details set Password = '%s' where GMail_ID = '%s' and Aadhar = '%s';" % (new_p, temp_g, temp_a)
cu.execute(query)
print()
print("Password changed successfully.")
loop = False
break
else:
print()
print('Invalid G-Mail ID/Aadhar. Please try again.')
elif choice_2 == 3:
break
else:
print()
print("Invalid choice. Please try again.")
co.commit()
# Managing the Customer's Account
def ManageAccount(t_g, t_a):
cu = co.cursor()
cu.execute("use ABC_CBS;")
loop = True
while loop:
print()
print(
"--------------------------------------------------------------------------------------------------------------")
print("1. View Account Details")
print("2. Deposit Money in Account")
print("3. Change User Details")
print("4. Exit")
print(
"--------------------------------------------------------------------------------------------------------------")
print()
choice_2 = int(input("Enter your choice: "))
if choice_2 == 1:
cu.execute("select * from user_details;")
data = cu.fetchall()
count = 0
for i in range(len(data)):
if t_g == data[i][2]:
count = count + 1
for i in range(len(data)):
if count == 1 and t_g == data[i][2]:
print()
print("Aadhar Number:", data[i][0])
print("Mobile Number:", data[i][1])
print("G-Mail ID:", data[i][2])
print("Name:", data[i][4])
print("Date Of Birth:", data[i][5])
print("Balance:", data[i][6])
break
elif count > 1:
for i in range(len(data)):
if t_g == data[i][2] and t_a == data[i][0]:
print()
print("Aadhar Number:", data[i][0])
print("Mobile Number:", data[i][1])
print("G-Mail ID:", data[i][2])
print("Name:", data[i][4])
print("Date Of Birth:", data[i][5])
print("Balance:", data[i][6])
break
break
elif choice_2 == 2:
print()
money = float(input("Please the enter amount you want to deposit: "))
if t_a:
pass
else:
t_a = int(input("Please enter your Aadhar Number: "))
cu.execute("select * from user_details")
data = cu.fetchall()
count = 0
for i in range(len(data)):
if t_g == data[i][2]:
count = count + 1
for i in range(len(data)):
if count == 1 and t_g == data[i][2]:
query = "update user_details set Balance = Balance + %s where GMail_ID = '%s' and Aadhar = %s" % (money, t_g, t_a)
cu.execute(query)
print()
print(money, "deposited.")
break
elif count > 1:
for i in range(len(data)):
if t_g == data[i][2] and t_a == data[i][0]:
query = "update user_details set Balance = Balance + %s where GMail_ID = '%s' and Aadhar = %s" % (money, t_g, t_a)
cu.execute(query)
print()
print(money, "deposited.")
break
break
co.commit()
elif choice_2 == 3:
print()
print("--------------------------------------------------------------------------------------------------------------")
print("1. Change G-Mail ID")
print("2. Change Mobile Number")
print("3. Change Password")
print("4. Go back to Main Menu")
print("--------------------------------------------------------------------------------------------------------------")
print()
choice_3 = int(input("Enter your choice: "))
if choice_3 == 1:
ChangeGMail(t_g)
logged_in = False
loop = False
elif choice_3 == 2:
ChangeMobile(t_g)
logged_in = False
loop = False
elif choice_3 == 3:
ChangePassword()
logged_in = False
loop = False
elif choice_3 == 4:
continue
elif choice_2 == 4:
loop = False
else:
print()
print("Invalid choice. Please try again. ")
co.commit()
# OTP Verification
def OTPVerification(mail):
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import random
import smtplib as smtp
smtp = smtp.SMTP('smtp.gmail.com', 587)
smtp.starttls()
smtp.login('[email protected]', 'nsiruyegnabfpawh')
otp = random.randrange(100000, 999999)
body = '''
Hello Customer, <br>
<br>
Greetings from ABC Bank. Your One Time Password(OTP) for Verification is given below.
<br>
<br>
OTP is %s
''' % otp
message = MIMEMultipart()
message['To'] = mail
message['From'] = "[email protected]"
message['Subject'] = '''OTP Verification'''
html_body = MIMEText(body, 'html')
message.attach(html_body)
smtp.sendmail('[email protected]', mail, message.as_string())
print()
print("OTP sent. Please check your mail.")
print()
iotp = int(input("Please enter the OTP sent in the given email: "))
if iotp == otp:
return True
else:
return False
print()
print("Welcome to ABC Bank, choose one of the options to get started:")
print()
while True:
print('''--------------------------------------------------------------------------------------------------------------
1. Create an Account
2. Log into an existing Account
3. Forgot Password
4. Exit
--------------------------------------------------------------------------------------------------------------
''')
choice = int(input("Enter your choice: "))
if choice == 1:
CreateAccount()
elif choice == 2:
LoginAccount()
elif choice == 3:
ChangePassword()
elif choice == 4:
break
else:
print()
print("Invalid choice. Please select again:")
print()
print()
print("Thank You for visiting ABC Bank, please come again!")
print()