Sep-24-2021, 06:17 AM
(Sep-21-2021, 09:35 PM)deanhystad Wrote: You are forcing each letter to be uppercase, lowercase, a number and a special character. That is rather stringent. Maybe you need to process every character and keep a tally of what requirements are met. After you process all the letters you can then decide if the password needs an upper case character to be valid.
(Sep-23-2021, 11:11 PM)SamHobbs Wrote: Yesterday I posted an alternative but I do not see it now. It can be modified to produce the same output if desired.
#import sys import string def checkPasswordStrength(password): if len(password) <= 6: print("Password must be at least 7 characters") return teststring = "luds" testlist = list(teststring) special_characters = '!@#$%^&*()' for letter in password : if letter.islower() : testlist[0] = 'X' elif letter.isupper() : testlist[1] = 'X' elif letter.isdigit() : testlist[2] = 'X' elif letter in special_characters : testlist[3] = 'X' test = ''.join(testlist) if test == "XXXX": print("Password is valid") return message = "Password is not valid; missing:" if testlist[0] == 'l': message += " lowercase letter "; if testlist[1] == 'u': message += " upper case letter "; if testlist[2] == 'd': message += " digit "; if testlist[3] == 's': message += " special character "; print(message) checkPasswordStrength('Billycash')
Thank you for the effort. The algo is neat and efficient.