Make an unique identifier for the user (stored in the session),
    so it can stay logged between requests.

    By hashing a snippet of the current password hash salt, it makes possible
    to automatically logout from all other devices just by changing
    (or refreshing) the password.

def get_uhmac(user, secret):
    """Make an unique identifier for the user (stored in the session),
    so it can stay logged between requests.

    By hashing a snippet of the current password hash salt, it makes possible
    to automatically logout from all other devices just by changing
    (or refreshing) the password.
    """
    secret = to_bytes(secret)
    key = '|'.join([
        hashlib.sha1(secret).hexdigest(),
        str(user.id),
        get_hash_extract(user.password),
    ])
    key = key.encode('utf8', 'ignore')
    mac = hmac.new(key, msg=None, digestmod=hashlib.sha512)
    mac = mac.hexdigest()[:50]
    uhmac = '{0}${1}'.format(user.id, mac)
    return uhmac