def Withdraw(self): clrscr() print_options(self.get_value("Username"), "Withdraw", self.get_value("Address"), self.get_value("Balance")) print( "Enter the amount you want to withdraw. Press any letter to go back." ) x = inpt("> ") if x.isdigit(): x = int(x) if x <= 0: print(f"\033[91mYou can't withdraw ${x}\033[0m") elif x > int(self.get_value("Balance")): print("\033[91mInsufficient Funds.\033[0m") else: self.append_transaction(f"Withdrawed ${x}.") self.Account["Balance"] -= x return else: return self.update_account() inpt("Press \033[91menter\033[0m to continue")
def show_transaction(self): clrscr() print("\033[93mTransaction Log\033[0m") x = 0 for i in self.Account["TransactionLog"].values(): print(i.replace(f"ID {x})", f"\033[94mID {x})\033[0m\n")) x += 1 inpt("Press \033[91menter\033[0m to exit.")
def show_all_info(self): clrscr() for key, value in self.Account.items(): if key == "TransactionLog" or key == "TFA_Code" or key == "Password" or key == "CreditCardNumber" or key == "SecurityCode": continue print(f"\033[93m{key}\033[0m: {value}") inpt("Press \033[91menter\033[0m to continue")
def Register(): clrscr() Account = {} inputs = { "First Name: ": 0, "Last Name: ": 1, "Username: "******"Password: "******"Credit Card Number: ": 4, "Security Code: ": 5, "Address: ": 6, "Postcode: ": 7, "Email: ": 8, "Phone: ": 9 } print(""" \033(0qqqqqqqq\033(B \033[93mRegister\033[0m \033(0qqqqqqqq\033(B Input \"\033[31m-1\033[0m\" to go back. Enter the following information... """) Account["TFA"] = "False" Account["Balance"] = "0" Account["TFA_Code"] = "0000000000" Account["TransactionLog"] = {} for i in inputs: n = (i.replace(": ", "")).replace(" ", "") while True: Account[n] = reg_ask(i, n) if Account[n] == False: return False elif Account[n] == True: continue break setup_file() with open("Accounts.txt", "rb") as f: x = json.loads(base64.b64decode(f.read()).decode()) with open("Accounts.txt", "wb") as fs: Account["Password"] = hashlib.blake2b( Account["Password"].encode()).hexdigest() x[Account["Username"]] = Account fs.write(base64.b64encode(json.dumps(x).encode())) LocalAcc = LocalAccount(Account) if LocalAcc.Vaild == True: LocalAcc.Home() return False
def main(): while True: clrscr() options = {"Login": Login, "Register": Register, "Exit": exit} print(""" \033(0qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\033(B \033[93mWelcome to the bank of The Boring Company.\033[0m \033(0qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\033(B Use the \033[91mArrow Keys\033[0m to navigate through the options and press \033[91mEnter\033[0m to select an option. """) print_menu(options) if getKeyMenu(options) == "return": break return
def Settings(self): while True: clrscr() self.options = { "Account Info": self.show_all_info, "Security": self.security, "Exit": "return" } print_options(self.get_value("Username"), "Settings", self.get_value("Address"), self.get_value("Balance"), self.options) if getKeyMenu(self.options) == "return": return True return False
def Home(self): while True: clrscr() self.options = { "Deposit Money": self.Deposit, "Withdraw Money": self.Withdraw, "Settings": self.Settings, "Back": "return" } print_options(self.get_value("Username"), "Home", self.get_value("Address"), self.get_value("Balance"), self.options) if getKeyMenu(self.options) == "return": return True return False
def security(self): while True: clrscr() self.options = { "Enable/Disable 2 Factor Authenthication": self.TFA, "Open Transaction Log": self.show_transaction, "Change Password": self.New_Password, "Change Phone Number": self.New_Phone, "Back": "return" } print_options(self.get_value("Username"), "Security", self.get_value("Address"), self.get_value("Balance"), self.options) if getKeyMenu(self.options) == "return": return True return False
def Deposit(self): clrscr() print_options(self.get_value("Username"), "Deposit", self.get_value("Address"), self.get_value("Balance")) print( "Enter the amount you want to deposit. Enter any letter to go back." ) x = inpt("> ") if x.isdigit(): x = int(x) if x <= 0: print("\033[91mYou can't deposit $", x, "\033[0m") else: self.append_transaction(f"Deposited ${x}.") self.Account["Balance"] += x return else: return self.update_account() inpt("Press \033[91menter\033[0m to continue")
def Login(): clrscr() print(""" \033(0qqqqq\033(B \033[93mLogin\033[0m \033(0qqqqq\033(B Input \"\033[91m-1\033[0m\" to go back. Enter of the following information... """) username = inpt("\033[93mUsername: \033[0m") if username == "-1": return False print("\033(0qqqqqqqqqqq\033(B") password = inpt("\033[93mPassword: \033[0m") if password == "-1": return False setup_file() with open("Accounts.txt", "rb") as f: Accounts = f.read() Accounts = json.loads(base64.b64decode(Accounts).decode()) if username in Accounts.keys(): LocalAcc = LocalAccount(Accounts[username]) if LocalAcc.Vaild and hashlib.blake2b( password.encode()).hexdigest() == LocalAcc.Account["Password"]: if LocalAcc.Account["TFA"] == "True": while True: tfa_code = inpt("\033[93m2FA Code: \033[0m") if hashlib.blake2b(tfa_code.encode()).hexdigest( ) == LocalAcc.Account["TFA_Code"]: LocalAcc.Home() break elif tfa_code == "-1": return False else: print("\033[91mInvaild 2FA Code.\033[0m") continue else: LocalAcc.Home() elif LocalAcc.Vaild and LocalAcc.Account[ "Password"] != hashlib.blake2b(password.encode()).hexdigest(): print("\033[91mIncorrect password.\033[0m") inpt("Press Enter to continue.") return False else: print( "\033[91mYour account has invaild account information. Please register again.\033[0m" ) inpt("Press Enter to continue.") return False else: print( "\033[91mThis account does not exist, make sure you register this account before you log in again.\033[0m" ) inpt("Press Enter to continue.") return False return True
options = {"Login": Login, "Register": Register, "Exit": exit} print(""" \033(0qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\033(B \033[93mWelcome to the bank of The Boring Company.\033[0m \033(0qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq\033(B Use the \033[91mArrow Keys\033[0m to navigate through the options and press \033[91mEnter\033[0m to select an option. """) print_menu(options) if getKeyMenu(options) == "return": break return if __name__ == "__main__": clrscr() print( "It's highly reccomended to use terminals that support ANSI.\n\nTerminals like:\n\tVisual Studio Code Integrated Terminal\n\tThe NEW Windows Terminal (https://github.com/microsoft/terminal)\n\nIs highly reccomended to use for this program to work perfectly." ) print("Press Enter 3 times.") for _ in range(3): inpt(f"Press Enter to continue. [{_}]") init() main() """ References: - https://en.wikipedia.org/wiki/ANSI_escape_code - https://ozzmaker.com/add-colour-to-text-in-python/ - https://voidinit.com/python/console/files