def is_valid_uid(u_id):
    """
    Given a u_id, returns whether it is a valid u_id.
    """
    data = get_data()
    for user in data["users"]:
        if user["u_id"] == u_id:
            return True
    return False
def is_valid_channel(channel_id):
    """
    Given a channel_id, returns whether it is a valid channel.
    """
    data = get_data()
    for channel in data["channels"]:
        if channel["channel_id"] == channel_id:
            return True

    return False
def is_valid_password(u_id, password):
    """
    Given a password determine whether it is a valid password for the u_id.
    """
    data = get_data()
    for user in data["users"]:
        for valid_u_id in user["u_id"]:
            if valid_u_id == u_id:
                if user["password"] == password:
                    return True
    return False
def is_valid_token(token):
    """
    A helper function used for TESTING and SERVER FUNCTIONS
    :param token: a string encoded with jwt received from auth_login or auth_register
    :return: boolean of whether the token has or hasn't been tampered with
    """
    data = get_data()

    for user in data["users"]:
        if token in user["valid_tokens"]:
            return True
    return False
def check_email(email):
    """
    Given an email determines whether it belongs to a user u_id.
    The function returns true if the email doesn't belong to a user
    and false if it does.
    """
    data = get_data()
    counter = 0
    # Check the email belongs to a user
    for user in data["users"]:
        if user["email"] == email:
            counter = 1
    if counter < 1:
        return True

    return False
def is_owner(user_id, channel_id):
    """
    This function returns a boolean indicating whether a user is an owner of a channel
    usage: pass in a valid token, a user_id, and a channel_id

    Important: This helper function will only work when the following functions are complete:
    auth_login
    channel_details
    """
    data = get_data()
    for channel in data["channels"]:
        if channel["channel_id"] == channel_id:
            for owner in channel["owner_members"]:
                if owner["u_id"] == user_id:
                    return True

    return False
def check_password(u_id, password):
    """
    Given a password determines whether it belongs to the correct user u_id.
    The function returns true if the password does not belong to the user and
    false if it does.
    """
    data = get_data()

    counter = 0
    # Check that the password belongs to the correct user
    for user in data["users"]:
        hashed_password = hashlib.sha256(password.encode()).hexdigest()
        if user["u_id"] == u_id and user["password"] == hashed_password:
            counter = 1
    if counter < 1:
        return True
    return False