Add comprehensive remote authentication system allowing users to log in from one device by authenticating from another trusted device. Features include: - Proof of Work (PoW) protection using PBKDF2-SHA512 to prevent abuse - Simple pairing codes (3 words) protected by dynamic PoW difficulty - Autocomplete pairing code input with error checking - Real-time WebSocket communication between devices Unlike device addition links and reset links with QR codes that only allow adding an authentication method, and that work offline over the duration of several days, this mechanism is strictly online, with 5 minute time limit.
21 lines
562 B
Python
21 lines
562 B
Python
import secrets
|
|
|
|
from paskia.util.wordlist import words
|
|
|
|
N_WORDS = 5
|
|
N_WORDS_SHORT = 3
|
|
|
|
wset = set(words)
|
|
|
|
|
|
def generate(n=N_WORDS, sep="."):
|
|
"""Generate a password of random words without repeating any word."""
|
|
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("."))
|