Created
December 15, 2015 08:57
-
-
Save eugena/f789b8bddc8743e6e2a9 to your computer and use it in GitHub Desktop.
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
import hashlib | |
from django.conf import settings | |
class EmailVerificationTokenGenerator(object): | |
""" | |
Strategy object used to generate and check tokens for the email | |
verification mechanism. | |
""" | |
def make_token(self, email): | |
""" | |
Returns a token that can be used once to do email verification | |
for the given email. | |
""" | |
return hashlib.sha1(settings.SECRET_KEY.encode() + email.encode()).hexdigest() | |
def check_token(self, email, token): | |
""" | |
Check that a token is correct for a given email. | |
""" | |
return token == hashlib.sha1(settings.SECRET_KEY.encode() + email.encode()).hexdigest() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment