Skip to content

Commit

Permalink
use 'secrets' module instead of 'random' to generate pin (#19)
Browse files Browse the repository at this point in the history
closes #18
  • Loading branch information
tibroc authored Jun 5, 2024
1 parent 899827f commit 0cb7008
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pairing-server/app.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
from quart import Quart, websocket
import json
import random
import secrets
import traceback
from atomicx import AtomicInt

Expand All @@ -22,7 +22,7 @@ def validate_client_config(config) -> bool:

def generate_pin():
while True:
pin = random.randrange(1e5, 1e6 - 1) # nosec: B311
pin = secrets.randbelow(int(1e6 - 1e5)) + int(1e5)
pin_free = pin not in pin_to_room
if pin_free:
return pin
Expand Down Expand Up @@ -124,7 +124,7 @@ async def handle_ws() -> None:
# pin provided by bbb plugin
pin = None
# verification pin after conn established
pairing_pin = random.randrange(1e3, 1e4 - 1) # nosec: B311
pairing_pin = secrets.randbelow(int(1e6 - 1e5)) + int(1e5)
forward_task = None
try:
data = await websocket.receive_json()
Expand Down

0 comments on commit 0cb7008

Please sign in to comment.