Last active
May 1, 2020 04:42
-
-
Save Cediddi/454701eb94c64c43be6c to your computer and use it in GitHub Desktop.
Django Middleware for fingerprinting browsers server-side. Useful for expiring auth tokens.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
#Disclaimer | |
- Use with caution | |
- Don't be evil | |
- Respect your users | |
""" | |
class FingerPrintMiddleware(object): | |
def process_request(self, request): | |
import hashlib | |
fingerprint_raw = "".join( | |
(request.META.get("HTTP_USER_AGENT", ""), | |
request.META.get("HTTP_ACCEPT_ENCODING", "")) | |
) | |
request.fingerprint = hashlib.md5( | |
fingerprint_raw.encode('utf-8')).hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment