-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank.py
132 lines (119 loc) · 5 KB
/
bank.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
import sqlite3
from passlib.hash import argon2
import time
import getpass # Import getpass module for password input
def create_user_table():
connection = sqlite3.connect('Bank Database.db')
c = connection.cursor()
c.execute('''
CREATE TABLE IF NOT EXISTS users (
user_id INTEGER PRIMARY KEY,
firstname TEXT,
lastname TEXT,
password_hash TEXT,
balance INTEGER
)
''')
connection.commit()
c.close()
def create_user(user_data):
connection = sqlite3.connect('Bank Database.db')
c = connection.cursor()
c.executemany("INSERT INTO users (firstname, lastname, password_hash, balance) VALUES (?, ?, ?, ?)", user_data)
connection.commit()
c.close()
def hash_password(password):
return argon2.hash(password)
def verify_password(password, hashed_password):
return argon2.verify(password, hashed_password)
def login(firstname):
password = getpass.getpass("Input your password:") # Use getpass to hide password input
connection = sqlite3.connect('Bank Database.db')
c = connection.cursor()
try:
c.execute('''SELECT * FROM users WHERE firstname = (?)''', (firstname,))
row = c.fetchone()
if row is None:
print("No account found for the entered username.")
return
stored_hashed_password = row[3]
# Omit printing hashed password
convert_1 = str(row[4])
print("Dear {} {}, welcome!\nYour balance is: #{}".format(row[1], row[2], convert_1))
print("How can I serve you?\n1. Deposit\n2. Withdraw\n3. Transfer\n4. Contact customer care\n5. Log out")
option = input("Enter your choice:")
if option == "1":
deposit = int(input("How much do you want to deposit:"))
process_3 = int(row[4]) + deposit
convert_3 = str(process_3)
init_2 = [
(convert_3, row[1])
]
c.executemany('''UPDATE users SET balance = (?) WHERE firstname = (?)''', init_2)
print("Transaction successful. New balance is: #{}".format(convert_3))
connection.commit()
elif option == "2":
withdraw = int(input("How much do you want to withdraw:"))
if withdraw + 20 > int(row[4]):
print("Insufficient balance!")
else:
process_2 = int(row[4]) - (withdraw + 20)
convert_2 = str(process_2)
init_1 = [
(convert_2, row[1])
]
c.executemany('''UPDATE users SET balance = (?) WHERE firstname = (?)''', init_1)
print("Transaction successful. New balance is: #{}".format(convert_2))
connection.commit()
elif option == "3":
receiver_firstname = input("Enter the receiver's first name:")
c.execute('''SELECT * FROM users WHERE firstname = (?)''', (receiver_firstname,))
receiver_row = c.fetchone()
if receiver_row is None:
print("Receiver not found.")
else:
transfer = int(input("How much do you want to transfer:"))
if transfer + 20 > int(row[4]):
print("Insufficient balance!")
else:
process_sender = int(row[4]) - (transfer + 20)
process_receiver = int(receiver_row[4]) + transfer
init_sender = [
(process_sender, row[1])
]
init_receiver = [
(process_receiver, receiver_row[1])
]
c.executemany('''UPDATE users SET balance = (?) WHERE firstname = (?)''', init_sender)
c.executemany('''UPDATE users SET balance = (?) WHERE firstname = (?)''', init_receiver)
print("Transfer successful")
connection.commit()
elif option == "4":
print("To contact our customer care line please dial the following number: 09062701708\nThank you")
elif option == "5":
print("Thank's for sharing your quality time with us")
elif option == "":
print("Please enter an option!")
else:
print("We don't understand. Try again later!")
except Exception as e:
print("Error:", e)
finally:
connection.close()
# Create user table and insert data
create_user_table()
create_user([
("Ife", "Mary", hash_password("pass"), 0),
("Anthony", "Truth", hash_password("password_2"), 0),
# ... (other user data)
])
while True:
login_user_firstname = input("Input your first name:")
print("*****Dream Wave Mobile Banking Chat Bot*****")
print("Initializing", end='', flush=True)
# Simulate a loading animation
for _ in range(5):
time.sleep(0.5) # Adjust sleep time as needed
print(".", end='', flush=True)
print("\nLogin process in progress...")
process_1 = login(login_user_firstname)