Skip to content

Commit

Permalink
Use secret
Browse files Browse the repository at this point in the history
  • Loading branch information
folix-01 committed Apr 16, 2024
1 parent 107ac28 commit 05ff6bf
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/collective/volto/formsupport/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
import pyotp
import base64

from plone.keyring.interfaces import IKeyManager
from zope.component import getUtility

from collections import deque


Expand Down Expand Up @@ -46,14 +49,16 @@ def get_blocks(context):

def generate_email_token(uid="", email=""):
"""Generates the email verification token"""
keymanager = getUtility(IKeyManager)

totp = pyotp.TOTP(base64.b32encode((uid + email).encode()))
totp = pyotp.TOTP(base64.b32encode((uid + email + keymanager.secret()).encode()))

return totp.now()


def validate_email_token(uid="", email="", token=""):
keymanager = getUtility(IKeyManager)

totp = pyotp.TOTP(base64.b32encode((uid + email).encode()))
totp = pyotp.TOTP(base64.b32encode((uid + email + keymanager.secret()).encode()))

return totp.verify(token, valid_window=EMAIL_OTP_LIFETIME)

0 comments on commit 05ff6bf

Please sign in to comment.