From 0b68393bb0c61e609f8d0252c75873b98e9b17b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C4=93teris=20Caune?= Date: Wed, 18 Oct 2017 16:33:32 +0300 Subject: [PATCH] Profile.token generated from os.urandom --- hc/accounts/models.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/hc/accounts/models.py b/hc/accounts/models.py index 03a4476e..d1f22729 100644 --- a/hc/accounts/models.py +++ b/hc/accounts/models.py @@ -1,6 +1,5 @@ -import base64 +from base64 import urlsafe_b64encode import os -import uuid from datetime import timedelta from django.conf import settings @@ -82,7 +81,7 @@ class Profile(models.Model): return self def prepare_token(self, salt): - token = str(uuid.uuid4()) + token = urlsafe_b64encode(os.urandom(24)).decode("utf-8") self.token = make_password(token, salt) self.save() return token @@ -119,7 +118,7 @@ class Profile(models.Model): emails.change_email(self.user.email, ctx) def set_api_key(self): - self.api_key = base64.urlsafe_b64encode(os.urandom(24)) + self.api_key = urlsafe_b64encode(os.urandom(24)) self.save() def checks_from_all_teams(self):