Skip to content

Commit 18cf1f7

Browse files
i have modified Bank application.md file, i have added validation feature when a old user came here and try to create new account it blocks and send print messsage try something else
kindly merge it, i am computer science student and this repo was very helpful sir. i will be my pleaser to add my code in your repo thankyou have a nice day Sandeep Prajapati
1 parent 601c553 commit 18cf1f7

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)