Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I condense a failed list of criteria with return False for the password validation?

def isValidPassword(password):
    if (len(password)<=8):
        print("Password must be at least 8 characters or more.")
        return False
    if any(digit.isdigit() for digit in password):
        print("Password must have at least single digit or more.")
        return False
    if any(digit.isupper() for digit in password):
        print("Password must have at least one uppercase letter or more.")
        return False
    if any(digit.islower() for digit in password):
        print("Password must have at least one lowercase letter or more.")
        return False
    return True

def confirmedPassword():
    isSecure = False ; isMatch = False
    password = "" ; reenterPassword = ""
    
    while(isSecure == False): 
        password = input("Enter your password: ")
        isSecure = isValidPassword(password)
    while(isMatch == False):
        reenterPassword = input("\nPlease re-enter your password: ")
        if (password == reenterPassword):
            isMatch = True ; print("Password is confirmed. Thank you.")
            print("The password you entered is approved and safe.")
        else:
            (password == reenterPassword)
            isMatch = False ; print("Password is not confirmed. Please try again.")
confirmedPassword()

If anyone can please help. It is appreciated. I had a hard time figuring out how to condense a failed list of criteria printed out when I input "ABC" to run the program.

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I changed your code to print out all the issues with the password before returning whether or not it is a valid password. I also fixed all of the if statements you had to correctly capture the password issue.

def isValidPassword(password):
    valid = True
    if (len(password) < 8):
        print("Password must be at least 8 characters or more.")
        valid = False
    if not any(digit.isdigit() for digit in password):
        print("Password must have at least single digit or more.")
        valid = False
    if not any(digit.isupper() for digit in password):
        print("Password must have at least one uppercase letter or more.")
        valid = False
    if not any(digit.islower() for digit in password):
        print("Password must have at least one lowercase letter or more.")
        valid = False
    
    return valid

def confirmedPassword():
    isSecure = False ; isMatch = False
    password = "" ; reenterPassword = ""
    
    while(not isSecure): 
        password = input("Enter your password: ")
        isSecure = isValidPassword(password)
    while(not isMatch):
        reenterPassword = input("\nPlease re-enter your password: ")
        if (password == reenterPassword):
            isMatch = True
            print("Password is confirmed. Thank you.")
            print("The password you entered is approved and safe.")
        else:
            isMatch = False
            print("Password is not confirmed. Please try again.")
confirmedPassword()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading