From 72a85b4bbba3c8c5fc8a066beb5fc407907cd412 Mon Sep 17 00:00:00 2001 From: Gouri Phadnis Date: Tue, 30 Sep 2025 10:34:07 +0530 Subject: [PATCH 1/3] Bug fix: Add uppercase and lowercase checks to password validator --- .../password-validator/PASSWORD_VALIDATOR.py | 53 ++++++++++--------- 1 file changed, 29 insertions(+), 24 deletions(-) diff --git a/PASSWORD RELATED/password-validator/PASSWORD_VALIDATOR.py b/PASSWORD RELATED/password-validator/PASSWORD_VALIDATOR.py index 76dfbef5..c72b0e8e 100644 --- a/PASSWORD RELATED/password-validator/PASSWORD_VALIDATOR.py +++ b/PASSWORD RELATED/password-validator/PASSWORD_VALIDATOR.py @@ -3,39 +3,44 @@ def passwordValidator(): """ Validates passwords to match specific rules - : return: str + :return: str """ - # display rules that a password must conform to print('\nYour password should: ') print('\t- Have a minimum length of 6;') print('\t- Have a maximum length of 12;') - print('\t- Contain at least an uppercase letter or a lowercase letter') + print('\t- Contain at least an uppercase letter;') + print('\t- Contain at least a lowercase letter;') print('\t- Contain at least a number;') print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);') print('\t- Not contain space(s).') - # get user's password + userPassword = input('\nEnter a valid password: ').strip() - # check if user's password conforms - # to the rules above + + # Length check if not(6 <= len(userPassword) <= 12): - message = 'Invalid Password..your password should have a minimum ' - message += 'length of 6 and a maximum length of 12' - return message + return 'Invalid Password..length must be between 6 and 12' + + # No spaces allowed if ' ' in userPassword: - message = 'Invalid Password..your password shouldn\'t contain space(s)' - return message - if not any(i in string.ascii_letters for i in userPassword): - message = 'Invalid Password..your password should contain at least ' - message += 'an uppercase letter and a lowercase letter' - return message - if not any(i in string.digits for i in userPassword): - message = 'Invalid Password..your password should contain at least a number' - return message - if not any(i in string.punctuation for i in userPassword): - message = 'Invalid Password..your password should contain at least a special character' - return message - else: - return 'Valid Password!' + return 'Invalid Password..shouldn\'t contain spaces' + + # Uppercase letter check + if not any(i.isupper() for i in userPassword): + return 'Invalid Password..should contain at least one uppercase letter' + + # Lowercase letter check + if not any(i.islower() for i in userPassword): + return 'Invalid Password..should contain at least one lowercase letter' + + # Number check + if not any(i.isdigit() for i in userPassword): + return 'Invalid Password..should contain at least one number' + + # Special character check + if not any(i in string.punctuation for i in userPassword): + return 'Invalid Password..should contain at least one special character' + + return 'Valid Password!' my_password = passwordValidator() -print(my_password) \ No newline at end of file +print(my_password) From a383cfd6a064e20a1b62d5b87acb2106fa80dc99 Mon Sep 17 00:00:00 2001 From: Gouri Phadnis Date: Tue, 30 Sep 2025 14:12:16 +0530 Subject: [PATCH 2/3] Bug fix: Added password_validator_fixed.py with proper uppercase and lowercase validation --- password_validator_fixed.py | 52 +++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 password_validator_fixed.py diff --git a/password_validator_fixed.py b/password_validator_fixed.py new file mode 100644 index 00000000..43b92ece --- /dev/null +++ b/password_validator_fixed.py @@ -0,0 +1,52 @@ +import string + +def passwordValidator(): + """ + Validates passwords to match specific rules + : return: str + """ + # display rules that a password must conform to + print('\nYour password should: ') + print('\t- Have a minimum length of 6;') + print('\t- Have a maximum length of 12;') + print('\t- Contain at least one uppercase letter;') + print('\t- Contain at least one lowercase letter;') + print('\t- Contain at least a number;') + print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);') + print('\t- Not contain space(s).') + + # get user's password + userPassword = input('\nEnter a valid password: ').strip() + + # check if user's password conforms to the rules above + if not (6 <= len(userPassword) <= 12): + message = 'Invalid Password..your password should have a minimum ' + message += 'length of 6 and a maximum length of 12' + return message + + if ' ' in userPassword: + message = 'Invalid Password..your password shouldn\'t contain space(s)' + return message + + if not any(i.isupper() for i in userPassword): + message = 'Invalid Password..your password should contain at least one uppercase letter' + return message + + if not any(i.islower() for i in userPassword): + message = 'Invalid Password..your password should contain at least one lowercase letter' + return message + + if not any(i in string.digits for i in userPassword): + message = 'Invalid Password..your password should contain at least a number' + return message + + if not any(i in string.punctuation for i in userPassword): + message = 'Invalid Password..your password should contain at least a special character' + return message + + return 'Valid Password!' + + +if __name__ == "__main__": + my_password = passwordValidator() + print(my_password) From b115f58da5115872da83533562b018ffd62fe824 Mon Sep 17 00:00:00 2001 From: Gouri Phadnis Date: Tue, 30 Sep 2025 14:31:45 +0530 Subject: [PATCH 3/3] Added fixed password validator script --- .../password_validator_fixed.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 PASSWORD RELATED/password-validator/password_validator_fixed.py diff --git a/PASSWORD RELATED/password-validator/password_validator_fixed.py b/PASSWORD RELATED/password-validator/password_validator_fixed.py new file mode 100644 index 00000000..90350f54 --- /dev/null +++ b/PASSWORD RELATED/password-validator/password_validator_fixed.py @@ -0,0 +1,47 @@ + +import string + +def passwordValidator(): + """ + Validates passwords to match specific rules + :return: str + """ + print('\nYour password should: ') + print('\t- Have a minimum length of 6;') + print('\t- Have a maximum length of 12;') + print('\t- Contain at least an uppercase letter;') + print('\t- Contain at least a lowercase letter;') + print('\t- Contain at least a number;') + print('\t- Contain at least a special character (such as @,+,£,$,%,*^,etc);') + print('\t- Not contain space(s).') + + userPassword = input('\nEnter a valid password: ').strip() + + # Length check + if not(6 <= len(userPassword) <= 12): + return 'Invalid Password..length must be between 6 and 12' + + # No spaces allowed + if ' ' in userPassword: + return 'Invalid Password..shouldn\'t contain spaces' + + # Uppercase letter check + if not any(i.isupper() for i in userPassword): + return 'Invalid Password..should contain at least one uppercase letter' + + # Lowercase letter check + if not any(i.islower() for i in userPassword): + return 'Invalid Password..should contain at least one lowercase letter' + + # Number check + if not any(i.isdigit() for i in userPassword): + return 'Invalid Password..should contain at least one number' + + # Special character check + if not any(i in string.punctuation for i in userPassword): + return 'Invalid Password..should contain at least one special character' + + return 'Valid Password!' + +my_password = passwordValidator() +print(my_password) \ No newline at end of file