import getpass


def get_pass(prompt, require=False):
    """Ask the user for a password.

    Args:
        prompt (unicode):
            The text to prompt the user with.

        require (bool, optional):
            Whether to require a result. If ``True``, this will keep prompting
            until a non-empty value is entered.

    Returns:
        bytes:
        The entered password.
    """
    prompt = str(prompt)

    if require:
        password = None

        while not password:
            password = getpass.getpass(prompt)
    else:
        password = getpass.getpass(prompt)

    return password