Skip to content

Commit c072a1f

Browse files
Refactor token generation to use secrets module
1 parent 64c3d9e commit c072a1f

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

rest_framework/authtoken/models.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import binascii
2-
import os
1+
import secrets
32

43
from django.conf import settings
54
from django.db import models
@@ -34,7 +33,7 @@ def save(self, *args, **kwargs):
3433

3534
@classmethod
3635
def generate_key(cls):
37-
return binascii.hexlify(os.urandom(20)).decode()
36+
return secrets.token_hex(20)
3837

3938
def __str__(self):
4039
return self.key

0 commit comments

Comments
 (0)