

def constant_time_compare(val1, val2):
    '\n    Returns True if the two strings are equal, False otherwise.\n\n    The time taken is independent of the number of characters that match.\n\n    For the sake of simplicity, this function executes in constant time only\n    when the two strings have the same length. It short-circuits when they\n    have different lengths. Since Django only uses it to compare hashes of\n    known expected length, this is acceptable.\n    '
    if (len(val1) != len(val2)):
        return False
    result = 0
    if (six.PY3 and isinstance(val1, bytes) and isinstance(val2, bytes)):
        for (x, y) in zip(val1, val2):
            result |= (x ^ y)
    else:
        for (x, y) in zip(val1, val2):
            result |= (ord(x) ^ ord(y))
    return (result == 0)

dataset/ETHPy150Open cloudera/hue/desktop/core/ext-py/Django-1.6.10/django/utils/crypto.py constant_time_compare/original