Skip to content

Instantly share code, notes, and snippets.

@eugena
Created December 15, 2015 08:57
Show Gist options
  • Save eugena/f789b8bddc8743e6e2a9 to your computer and use it in GitHub Desktop.
Save eugena/f789b8bddc8743e6e2a9 to your computer and use it in GitHub Desktop.
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