import pickle


def get_challenge_by_name(database, challenge_name, ctf_channel_id):
    """
    Fetch a Challenge object in the database with a given name and ctf channel
    ID.
    Return the matching Challenge object if found, or None otherwise.
    """
    ctfs = pickle.load(open(database, "rb"))
    for ctf in ctfs:
        if ctf.channel_id == ctf_channel_id:
            for challenge in ctf.challenges:
                if challenge.name == challenge_name:
                    return challenge

    return None