diff --git a/app/api/views/auth.py b/app/api/views/auth.py index 1adc2131..4dd57645 100644 --- a/app/api/views/auth.py +++ b/app/api/views/auth.py @@ -1,4 +1,5 @@ -import random +import secrets +import string import facebook import google.oauth2.credentials @@ -102,7 +103,7 @@ def auth_register(): Session.flush() # create activation code - code = "".join([str(random.randint(0, 9)) for _ in range(6)]) + code = "".join([str(secrets.choice(string.digits)) for _ in range(6)]) AccountActivation.create(user_id=user.id, code=code) Session.commit() @@ -194,7 +195,7 @@ def auth_reactivate(): Session.commit() # create activation code - code = "".join([str(random.randint(0, 9)) for _ in range(6)]) + code = "".join([str(secrets.choice(string.digits)) for _ in range(6)]) AccountActivation.create(user_id=user.id, code=code) Session.commit() diff --git a/app/utils.py b/app/utils.py index 71a87232..42418824 100644 --- a/app/utils.py +++ b/app/utils.py @@ -1,4 +1,5 @@ import random +import secrets import string import time import urllib.parse @@ -27,7 +28,7 @@ def random_words(): """Generate a random words. Used to generate user-facing string, for ex email addresses""" # nb_words = random.randint(2, 3) nb_words = 2 - return "_".join([random.choice(_words) for i in range(nb_words)]) + return "_".join([secrets.choice(_words) for i in range(nb_words)]) def random_string(length=10, include_digits=False): @@ -36,7 +37,7 @@ def random_string(length=10, include_digits=False): if include_digits: letters += string.digits - return "".join(random.choice(letters) for _ in range(length)) + return "".join(secrets.choice(letters) for _ in range(length)) def convert_to_id(s: str):