Skip to content

Commit b7abe2e

Browse files
committed
chore:use secrets.token_urlsafe instead of random.randint #238
1 parent 1c92409 commit b7abe2e

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

captcha/views.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import json
22
import os
33
import random
4+
import secrets
45
import subprocess
56
import tempfile
67
from io import BytesIO
@@ -162,9 +163,7 @@ def captcha_audio(request, key):
162163
else:
163164
text = ", ".join(list(text))
164165
path = str(
165-
os.path.join(
166-
tempfile.gettempdir(), f"{key}_{random.randint(100_000, 999_999)}.wav"
167-
)
166+
os.path.join(tempfile.gettempdir(), f"{key}_{secrets.token_urlsafe(6)}.wav")
168167
)
169168
subprocess.run([settings.CAPTCHA_FLITE_PATH, "-t", text, "-o", path])
170169

@@ -186,7 +185,7 @@ def captcha_audio(request, key):
186185
arbnoisepath = str(
187186
os.path.join(
188187
tempfile.gettempdir(),
189-
f"{key}_{random.randint(100_000, 999_999)}_noise.wav",
188+
f"{key}_{secrets.token_urlsafe(6)}_noise.wav",
190189
)
191190
)
192191
subprocess.run(
@@ -206,7 +205,7 @@ def captcha_audio(request, key):
206205
mergedpath = str(
207206
os.path.join(
208207
tempfile.gettempdir(),
209-
f"{key}_{random.randint(100_000, 999_999)}_merged.wav",
208+
f"{key}_{secrets.token_urlsafe(6)}_merged.wav",
210209
)
211210
)
212211
subprocess.run(

0 commit comments

Comments
 (0)