Major cleanup and refactoring of the backend (frontend not fully updated).

This commit is contained in:
Leo Vasanko
2025-08-01 12:32:27 -06:00
parent 0cfa622bf1
commit c5e5fe23e3
16 changed files with 451 additions and 920 deletions

View File

@@ -2,8 +2,18 @@ import secrets
from .wordlist import words
N_WORDS = 5
def generate(n=4, sep="."):
wset = set(words)
def generate(n=N_WORDS, sep="."):
"""Generate a password of random words without repeating any word."""
wl = list(words)
wl = words.copy()
return sep.join(wl.pop(secrets.randbelow(len(wl))) for i in range(n))
def is_well_formed(passphrase: str, n=N_WORDS, sep=".") -> bool:
"""Check if the passphrase is well-formed according to the regex pattern."""
p = passphrase.split(sep)
return len(p) == n and all(w in wset for w in passphrase.split("."))