from django.core.exceptions import ValidationError


class ComplexityValidator:
    """Require mixed character classes for investor and staff passwords."""

    def validate(self, password, user=None):
        checks = [
            any(c.islower() for c in password),
            any(c.isupper() for c in password),
            any(c.isdigit() for c in password),
            any(not c.isalnum() for c in password),
        ]
        if not all(checks):
            raise ValidationError(
                "Password must include uppercase, lowercase, number and special character.",
                code="password_complexity",
            )

    def get_help_text(self):
        return "Your password must include uppercase, lowercase, number and special character."
