Use 'secrets' module to generate secrets

Python 3.6+ has this
This commit is contained in:
YuviPanda
2021-03-29 16:00:35 +05:30
parent cebb1f3e22
commit 9f6467be05
3 changed files with 6 additions and 3 deletions

View File

@@ -8,6 +8,7 @@ import hashlib
import inspect
import os
import random
import secrets
import socket
import ssl
import sys
@@ -319,7 +320,7 @@ def hash_token(token, salt=8, rounds=16384, algorithm='sha512'):
"""
h = hashlib.new(algorithm)
if isinstance(salt, int):
salt = b2a_hex(os.urandom(salt))
salt = b2a_hex(secrets.token_bytes(salt))
if isinstance(salt, bytes):
bsalt = salt
salt = salt.decode('utf8')