From 18cf1f7383dfa9ef1592dac1aa42d054fa1b2cf7 Mon Sep 17 00:00:00 2001 From: sandeeep-parajapati <6392424180sandeep@gmail.com> Date: Thu, 25 Jan 2024 12:37:33 +0530 Subject: [PATCH] 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 --- Projects/Bank Application.md | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/Projects/Bank Application.md b/Projects/Bank Application.md index c2087f1..e4cbdcc 100644 --- a/Projects/Bank Application.md +++ b/Projects/Bank Application.md @@ -58,11 +58,22 @@ class BankApp: ''') self.conn.commit() - def create_account(self, username, password): + def user_already_exist(self): + username = input("Enter a username: ") + self.cursor.execute("SELECT username FROM accounts WHERE username = ?", (username)) + account = self.cursor.fetchone() + if account: + print("Username already in use, use another new one") + self.user_already_exist() + else : + return username + + def create_account(self,username,password): + hashed_password = hashlib.sha256(password.encode()).hexdigest() - self.cursor.execute("INSERT INTO accounts (username, password, balance) VALUES (?, ?, ?)", - (username, hashed_password, 0.0)) + self.cursor.execute("INSERT INTO accounts (username, password, balance) VALUES (?,?,?)",(username,hashed_password,0.0)) self.conn.commit() + print("Account created successfully.") def login(self, username, password): hashed_password = hashlib.sha256(password.encode()).hexdigest() @@ -119,10 +130,9 @@ def main(): choice = input("Select an operation: ") if choice == "1": - username = input("Enter a username: ") + username = bank_app.user_already_exist() password = input("Enter a password: ") bank_app.create_account(username, password) - print("Account created successfully.") elif choice == "2": username = input("Enter your username: ")