Skip to content

Commit 644be13

Browse files
committed
generate short codes with secrets, not random
1 parent 6b959a3 commit 644be13

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

app/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import random
21
import re
2+
import secrets
33
import string
44
from urllib.parse import urlsplit, urlunsplit
55

@@ -11,7 +11,7 @@
1111

1212
def generate_short_code(length: int = SHORT_CODE_LENGTH) -> str:
1313
chars = string.ascii_letters + string.digits
14-
return "".join(random.choices(chars, k=length))
14+
return "".join(secrets.choice(chars) for _ in range(length))
1515

1616
def validate_url(url: str) -> bool:
1717
if len(url) > MAX_URL_LENGTH:

0 commit comments

Comments
 (0)