Browse Source

Merge branch 'master' of github.com:matrix-org/sydent

eleutheria 4 years ago
parent
commit
c3879957b0
3 changed files with 11 additions and 4 deletions
  1. 2 3
      sydent/db/valsession.py
  2. 0 1
      sydent/sydent.py
  3. 9 0
      sydent/util/tokenutils.py

+ 2 - 3
sydent/db/valsession.py

@@ -42,8 +42,7 @@ class ThreePidValSessionStore:
 
         sid = self.addValSession(medium, address, clientSecret, time_msec(), commit=False)
 
-        tokenString = sydent.util.tokenutils.generateNumericTokenOfLength(
-            int(self.sydent.cfg.get('email', 'token.length')))
+        tokenString = sydent.util.tokenutils.generateTokenForMedium(medium)
 
         cur.execute("insert into threepid_token_auths (validationSession, token, sendAttemptNumber) values (?, ?, ?)",
                     (sid, tokenString, -1))
@@ -127,4 +126,4 @@ class ThreePidValSessionStore:
         if not s.validated:
             raise SessionNotValidatedException()
 
-        return s
+        return s

+ 0 - 1
sydent/sydent.py

@@ -66,7 +66,6 @@ class Sydent:
         'replication.https.port': '4434',
         'obey_x_forwarded_for': False,
         # email
-        'token.length': '6',
         'email.template': 'res/email.template',
         'email.from': 'Sydent Validation <noreply@{hostname}>',
         'email.subject': 'Your Validation Token',

+ 9 - 0
sydent/util/tokenutils.py

@@ -17,5 +17,14 @@
 import string
 import random
 
+def generateTokenForMedium(medium):
+    if medium == 'email':
+        return generateAlphanumericTokenOfLength(32)
+    else:
+        return generateNumericTokenOfLength(6)
+
 def generateNumericTokenOfLength(length):
     return "".join([random.choice(string.digits) for _ in range(length)])
+
+def generateAlphanumericTokenOfLength(length):
+    return "".join([random.choice(string.digits + string.ascii_lowercase + string.ascii_uppercase) for _ in range(length)])