"""
PasswordStrengthAnalyzer
Generated by Eden via recursive self-improvement
2025-10-27 16:39:50.706699
"""

class PasswordStrengthAnalyzer:
    """
    A capability that analyzes password strength by evaluating various security metrics.
    
    This class provides methods to check if a password meets minimum complexity requirements,
    checks against compromised passwords, calculates entropy, and ensures uniqueness.
    
    Example Usage:
        analyzer = PasswordStrengthAnalyzer()
        password = "Qwerty@123!"
        score = analyzer.analyze_password(password)
        print(f"Password strength score: {score}/5")
        # Output will be based on the password's strength
    """

    def __init__(self):
        self.bad_passwords = ["password", "123456", "qwerty"]
    
    def _check_min_length(self, password):
        """Check if the password meets minimum length requirement."""
        return len(password) >= 8
    
    def _check_complexity(self, password):
        """Verify that the password contains a mix of character types."""
        has_upper = any(c.isupper() for c in password)
        has_lower = any(c.islower() for c in password)
        has_digit = any(c.isdigit() for c in password)
        has_special = any(c in "!@#$%^&*()" for c in password)
        
        return (has_upper + has_lower + has_digit + has_special) >= 3
    
    def _check_entropy(self, password):
        """Estimate the entropy of the password."""
        import math
        uppercase = len([c for c in password if c.isupper()])
        lowercase = len([c for c in password if c.islower()])
        digits = len([c for c in password if c.isdigit()])
        special_chars = len([c for c in password if c in "!@#$%^&*()"])
        
        total_possible = (26**uppercase) * (26**lowercase) * (10**digits) * (8**special_chars)
        entropy = math.log2(total_possible) / len(password)
        return entropy >= 30  # Higher threshold for better security
    
    def _check_uniqueness(self, password):
        """Ensure the password is not in a list of compromised passwords."""
        return password.lower() not in self.bad_passwords
    
    def analyze_password(self, password):
        """
        Analyzes the given password and returns a strength score.
        
        Args:
            password (str): The password to evaluate.
            
        Returns:
            int: A score between 0 and 5 indicating password strength,
                 where 5 is the strongest.
        """
        checks = [
            self._check_min_length(password),
            self._check_complexity(password),
            self._check_entropy(password),
            self._check_uniqueness(password)
        ]
        
        # Additional points for longer passwords
        length_bonus = min(len(password) // 20, 1)
        
        score = sum(checks) + length_bonus
        return score if score <=5 else 5
    
    def get_password_health_tip(self, password):
        """
        Provides a health tip based on password analysis.
        
        Args:
            password (str): The password to evaluate.
            
        Returns:
            str: A security recommendation for the given password.
        """
        score = self.analyze_password(password)
        if score < 2:
            return "Password is very weak. Consider using a longer and more complex password."
        elif 3 <= score <4:
            return "Password could be improved with additional complexity or length."
        else:
            return "Password is strong. Well done!"