Browse Source

Use secrets.token_urlsafe

pull/340/head
Pēteris Caune 5 years ago
parent
commit
22ef024885
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
1 changed files with 4 additions and 5 deletions
  1. +4
    -5
      hc/accounts/models.py

+ 4
- 5
hc/accounts/models.py View File

@ -1,6 +1,5 @@
from base64 import urlsafe_b64encode
from datetime import timedelta from datetime import timedelta
import os
from secrets import token_urlsafe
import uuid import uuid
from django.conf import settings from django.conf import settings
@ -76,7 +75,7 @@ class Profile(models.Model):
return settings.SITE_ROOT + path return settings.SITE_ROOT + path
def prepare_token(self, salt): def prepare_token(self, salt):
token = urlsafe_b64encode(os.urandom(24)).decode()
token = token_urlsafe(24)
self.token = make_password(token, salt) self.token = make_password(token, salt)
self.save() self.save()
return token return token
@ -240,8 +239,8 @@ class Project(models.Model):
return self.owner_profile.check_limit - num_used return self.owner_profile.check_limit - num_used
def set_api_keys(self): def set_api_keys(self):
self.api_key = urlsafe_b64encode(os.urandom(24)).decode()
self.api_key_readonly = urlsafe_b64encode(os.urandom(24)).decode()
self.api_key = token_urlsafe(nbytes=24)
self.api_key_readonly = token_urlsafe(nbytes=24)
self.save() self.save()
def team(self): def team(self):


Loading…
Cancel
Save