Skip to content

Commit 8bc0bd4

Browse files
[chores] Refactored generate_django_secret_key.py: replaced random with secrets
See https://docs.python.org/3/library/secrets.html for more information.
1 parent 7e91671 commit 8bc0bd4

File tree

1 file changed

+4
-14
lines changed

1 file changed

+4
-14
lines changed
Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
#!/usr/bin/env python
2-
"""Pseudo-random django secret key generator"""
3-
from __future__ import print_function
2+
# This script will generate a random 50-character string suitable for use as a SECRET_KEY.
3+
import secrets
44

5-
import random
6-
7-
chars = (
8-
"abcdefghijklmnopqrstuvwxyz"
9-
"ABCDEFGHIJKLMNOPQRSTUVXYZ"
10-
"0123456789"
11-
"#()^[]-_*%&=+/"
12-
)
13-
14-
SECRET_KEY = "".join([random.SystemRandom().choice(chars) for i in range(50)])
15-
16-
print(SECRET_KEY)
5+
charset = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*(-_=+)'
6+
print(''.join(secrets.choice(charset) for _ in range(50)))

0 commit comments

Comments
 (0)