auth.py python
20 lines 599 B
Raw
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab NXP-b DONE: independent BV-r2 pass + ISR (SD-17) Human minor ⚠ breaking 1 day ago
1 """Session credential and CSRF generation for the local app server (§Q0.6)."""
2
3 from __future__ import annotations
4
5 import secrets
6
7
8 def generate_session_credential() -> str:
9 """Return a cryptographically secure token with at least 128 bits of entropy."""
10 return secrets.token_hex(16)
11
12
13 def generate_csrf_token() -> str:
14 """Return a CSRF token with at least 128 bits of entropy."""
15 return secrets.token_hex(16)
16
17
18 def constant_time_equal(a: str, b: str) -> bool:
19 """Compare two strings in constant time."""
20 return secrets.compare_digest(a.encode("utf-8"), b.encode("utf-8"))
File History 1 commit
sha256:c07f2f34a0db9f43fe866f157d1935322008545ff8940c06c7c921eb219c55ab NXP-b DONE: independent BV-r2 pass + ISR (SD-17) Human minor 1 day ago