from typing import Any


def ensure_password(value: Any) -> str:
    if not isinstance(value, str):
        raise TypeError("Password must be a string")
    value = value.strip()
    if len(value) < 8:
        raise ValueError("Password must be at least 8 characters")
    elif value.strip() == "":
        raise ValueError("Password cannot be empty")
    return value


def ensure_username(value: str) -> str:
    value = value.strip()
    if len(value) < 3:
        raise ValueError("Username must be at least 3 characters")
    elif value.lower() in ["admin", "moderator", "админ", "модератор"]:
        raise ValueError("Login is already taken")
    return value
