Skip to content

Commit c442167

Browse files
authored
Merge pull request #5 from sandeeep-prajapati/main
i have modified Bank application.md file
2 parents 601c553 + 18cf1f7 commit c442167

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

Projects/Bank Application.md

+15-5
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,22 @@ class BankApp:
5858
''')
5959
self.conn.commit()
6060

61-
def create_account(self, username, password):
61+
def user_already_exist(self):
62+
username = input("Enter a username: ")
63+
self.cursor.execute("SELECT username FROM accounts WHERE username = ?", (username))
64+
account = self.cursor.fetchone()
65+
if account:
66+
print("Username already in use, use another new one")
67+
self.user_already_exist()
68+
else :
69+
return username
70+
71+
def create_account(self,username,password):
72+
6273
hashed_password = hashlib.sha256(password.encode()).hexdigest()
63-
self.cursor.execute("INSERT INTO accounts (username, password, balance) VALUES (?, ?, ?)",
64-
(username, hashed_password, 0.0))
74+
self.cursor.execute("INSERT INTO accounts (username, password, balance) VALUES (?,?,?)",(username,hashed_password,0.0))
6575
self.conn.commit()
76+
print("Account created successfully.")
6677

6778
def login(self, username, password):
6879
hashed_password = hashlib.sha256(password.encode()).hexdigest()
@@ -119,10 +130,9 @@ def main():
119130
choice = input("Select an operation: ")
120131

121132
if choice == "1":
122-
username = input("Enter a username: ")
133+
username = bank_app.user_already_exist()
123134
password = input("Enter a password: ")
124135
bank_app.create_account(username, password)
125-
print("Account created successfully.")
126136

127137
elif choice == "2":
128138
username = input("Enter your username: ")

0 commit comments

Comments
 (0)