Skip to content

Commit

Permalink
chore:use secrets.token_urlsafe instead of random.randint #238
Browse files Browse the repository at this point in the history
  • Loading branch information
mbi committed Dec 18, 2024
1 parent 1c92409 commit b7abe2e
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions captcha/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import json
import os
import random
import secrets
import subprocess
import tempfile
from io import BytesIO
Expand Down Expand Up @@ -162,9 +163,7 @@ def captcha_audio(request, key):
else:
text = ", ".join(list(text))
path = str(
os.path.join(
tempfile.gettempdir(), f"{key}_{random.randint(100_000, 999_999)}.wav"
)
os.path.join(tempfile.gettempdir(), f"{key}_{secrets.token_urlsafe(6)}.wav")
)
subprocess.run([settings.CAPTCHA_FLITE_PATH, "-t", text, "-o", path])

Expand All @@ -186,7 +185,7 @@ def captcha_audio(request, key):
arbnoisepath = str(
os.path.join(
tempfile.gettempdir(),
f"{key}_{random.randint(100_000, 999_999)}_noise.wav",
f"{key}_{secrets.token_urlsafe(6)}_noise.wav",
)
)
subprocess.run(
Expand All @@ -206,7 +205,7 @@ def captcha_audio(request, key):
mergedpath = str(
os.path.join(
tempfile.gettempdir(),
f"{key}_{random.randint(100_000, 999_999)}_merged.wav",
f"{key}_{secrets.token_urlsafe(6)}_merged.wav",
)
)
subprocess.run(
Expand Down

0 comments on commit b7abe2e

Please sign in to comment.