Andrei Neagoie Python Today
Args: max_attempts: Maximum attempts allowed in time window window_seconds: Time window in seconds """ self.max_attempts = max_attempts self.window_seconds = window_seconds self.attempts: Dict[str, list] = {}
@staticmethod def hash_password(password: str) -> str: """ Hash password using SHA-256 with salt
def validate_token(self, token: str) -> Dict: """ Validate and decode JWT token andrei neagoie python
Requirements: - Minimum 8 characters - At least 1 uppercase letter - At least 1 lowercase letter - At least 1 digit - At least 1 special character
Raises: AuthenticationError: If token is invalid or user not found """ payload = self.token_manager.validate_token(token) user_id = payload.get('user_id') email = payload.get('email') Args: max_attempts: Maximum attempts allowed in time window
if not re.search(r'\d', password): raise ValidationError("Password must contain at least one digit")
# Next attempt should lock account with pytest.raises(AuthenticationError, match="Account locked"): auth_service.login("test@example.com", "ValidPass123!", "127.0.0.1") token: str) ->
def test_token_validation(self, auth_service): auth_service.register_user("test@example.com", "ValidPass123!") token, _ = auth_service.login("test@example.com", "ValidPass123!", "10.0.0.1")