import hashlib


def hash_string(source, length=18):
    """Generate truncated to length hexdigest for provided source string.

    :param source: string to computes hash from.
    :type source: basestring
    :param length: truncate hash to the specified length.
    :type length: int
    :rtype: str
    """
    return hashlib.sha256(source.encode('utf-8')).hexdigest()[0:length]