From 65a6216eff69b44ae4a55ea282255115c1a2ac7b Mon Sep 17 00:00:00 2001 From: spekulaas Date: Sat, 11 Nov 2023 20:45:31 +0100 Subject: [PATCH] added min amount of keys to username and pass --- goodchain/src/classes/User.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/goodchain/src/classes/User.py b/goodchain/src/classes/User.py index 17190ad..2e32c05 100644 --- a/goodchain/src/classes/User.py +++ b/goodchain/src/classes/User.py @@ -30,6 +30,10 @@ class User: input_username = input("Username: ") input_password = getpass("Password: ") + if len(input_username) < 4 or len(input_password) < 4: + print(f"{UtilityHelper.errorMessage('Username or password is too short, inputs should be atleast 4 characters long')}") + return False + hashed_password = UtilityHelper.computeHash(input_password) # check if username is already taken @@ -58,8 +62,13 @@ class User: # Get new password new_password = getpass("Enter your new password: ") check_new_password = getpass("Enter your new password again: ") - while new_password != check_new_password: - print(f"{UtilityHelper.warningMessage('Passwords do not match')}") + + + while new_password != check_new_password and len(new_password) < 4: + if len(new_password) < 4: + print(f"{UtilityHelper.warningMessage('Password should be atleast 4 characters long')}") + if new_password != check_new_password: + print(f"{UtilityHelper.warningMessage('Passwords do not match')}") new_password = getpass("Enter your new password: ") check_new_password = getpass("Enter your new password again: ") @@ -76,6 +85,9 @@ class User: # Get new username new_username = input("Enter your new username: ") + if len(new_username) < 4: + print(f"{UtilityHelper.errorMessage('Username should be atleast 4 characters long')}") + return False # check if username is already taken if self.db.fetchUserByUsername(new_username): print(f"{UtilityHelper.errorMessage('Username already taken')}")