'''
Password Verifier

Summary
A program that reads a single string and determines whether or not it is a valid password based on predetermined parameters

'''
password = input("Enter Password: ")

def check_length(password):
    if len(password) >= 6:
        return True
    else:
        return False

def check_digits(password): 
    digits = 0
    for character in range(0, len(password), 1):
        if password[character].isdigit():
            digits += 1
        if digits >= 1:
            return True
    else:
        return False
        
def check_lowercase(password): 
    lowercase = 0
    for character in range(0, len(password), 1):
        if password[character].islower():
            lowercase += 1
        if lowercase >= 2:
            return True
    else:
        return False        
        
def check_uppercase(password): 
    uppercase = 0
    for character in range(0, len(password), 1):
        if password[character].isupper():
            uppercase += 1
        if uppercase >= 1:
            return True
    else:
        return False 
      
def check_specialcharacters(password):
    specialcharacters = 0
    special_list = ' ! @ # $ % & _ = '
    for character in range(0, len(password), 1):
        if password[character] in special_list:
            specialcharacters += 1
        if specialcharacters >= 1:
            return True
    else:
        return False
    
def check_duplicates(password):
    duplicates = 0
    for character in range(0, len(password), 1):
        if character != 0:
            item = password[character]
            if item in password[:character]:
                duplicates += 1
            if duplicates >= 1:
                return False
    else:
        return True 
            
def main():
    if check_lowercase(password) and check_length(password) and check_uppercase(password) and check_digits(password) and check_specialcharacters(password) and check_duplicates(password) == True:
        print ("The password is valid")
    else:
        print ("The password is invalid")
        
        if check_digits(password) == False:
            print("The password needs at least 1 number")
            
        elif check_uppercase(password) == False:
            print("The password needs at least 1 uppercase character")
            
        elif check_lowercase(password) == False:
            print("The password needs at least 2 lowercase characters")
            
        elif check_length(password) == False:
            print("The password needs to be at least 6 characters") 
        
        elif check_specialcharacters(password) == False:
            print("The password needs one of the following characters: ! @ # $ % & _ =")
        
        elif check_duplicates(password) == False:
            print("The password cannot contain duplicate characters")
main()
Scroll to Top