When data leaves your program and comes back, as a cookie, a link in an email or a field in a form, nothing stops the other side from changing it. A message authentication code, an HMAC, solves that: it is a short value computed from the data and a secret key, which only the holder of the key can make. If the data or the code was changed, the check fails. This lesson builds a small signed token, with an expiry, and names the things that can still go wrong.
More lessons in Complete Python Programming