Strong Password

  • + 0 comments
    def minimumNumber(n, password):
        # Return the minimum number of characters to make the password strong
        len_required = 6
        has_digit = False
        has_lower_case = False
        has_upper_case = False
        has_special_char = False 
        special_char = set("!@#$%^&*()-+")
        char_required = 4
        for i in password:
            if "0" <= i <= "9" and not has_digit:
                has_digit = True
                char_required -= 1
            elif "a" <= i <= "z" and not has_lower_case:
                has_lower_case = True
                char_required -= 1
            elif "A" <= i <= "Z" and not has_upper_case:
                has_upper_case = True
                char_required -= 1
            elif i in special_char and not has_special_char:
                has_special_char = True
                char_required -= 1
                
        if n >= len_required:
            return char_required
            
        len_diff = len_required - n
                     
        return len_diff if len_diff > char_required else char_required