Andrei Neagoie Python [cracked] — Full HD

def test_verify_wrong_password(self): hasher = PasswordHasher() hashed = hasher.hash_password("Correct123!") assert not hasher.verify_password("Wrong456!", hashed) class TestAuthenticationService: @pytest.fixture def auth_service(self): return AuthenticationService(secret_key="test-secret-key-123")

def test_expired_token(self, auth_service): # Create service with very short expiry service = AuthenticationService(secret_key="test-key") service.token_manager.token_expiry_minutes = 0 # Expired immediately service.register_user("test@example.com", "ValidPass123!") token, _ = service.login("test@example.com", "ValidPass123!", "10.0.0.1") with pytest.raises(AuthenticationError, match="expired"): service.verify_token(token) if name == " main ": # Initialize service with secure secret key (use environment variable in production) auth_service = AuthenticationService(secret_key="your-strong-secret-key-here") andrei neagoie python

class ValidationError(AuthenticationError): """Raised when input validation fails""" pass _ = service.login("test@example.com"

def check_rate_limit(self, key: str) -> bool: """ Check if rate limit is exceeded for given key Args: key: Identifier for rate limiting (e.g., email or IP) Returns: True if under limit, False if exceeded Raises: RateLimitExceededError: If rate limit is exceeded """ now = time.time() # Clean up old attempts if key in self.attempts: self.attempts[key] = [ attempt_time for attempt_time in self.attempts[key] if now - attempt_time < self.window_seconds ] # Check if limit exceeded if len(self.attempts.get(key, [])) >= self.max_attempts: wait_time = self.window_seconds - (now - self.attempts[key][0]) raise RateLimitExceededError( f"Too many attempts. Please try again in int(wait_time) seconds" ) return True "10.0.0.1") with pytest.raises(AuthenticationError

def test_account_lockout(self, auth_service): auth_service.register_user("test@example.com", "ValidPass123!") # Try wrong password 5 times (max_failed_attempts=5) for _ in range(5): with pytest.raises(InvalidPasswordError): auth_service.login("test@example.com", "wrong", "127.0.0.1") # Next attempt should lock account with pytest.raises(AuthenticationError, match="Account locked"): auth_service.login("test@example.com", "ValidPass123!", "127.0.0.1")