Created
June 4, 2012 16:27
-
-
Save danriti/2869387 to your computer and use it in GitHub Desktop.
Generate user activation key for a Django user
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
""" | |
The activation key for the ``UserProfile`` will be a | |
SHA1 hash, generated from a combination of the ``User``'s | |
email and a random salt. | |
""" | |
salt = hashlib.sha1(str(random.random())).hexdigest()[:5] | |
email = user.email | |
if isinstance(email, unicode): | |
email = email.encode('utf-8') | |
activation_key = hashlib.sha1(salt+email).hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For anybody landing here, note that sha1 is no longer considered secure. SHA256 should be used instead.