Secure Passwords, UUID v4 & Unix Timestamp Essentials
Why cryptographic randomness matters for passwords and UUIDs, plus avoiding the classic 10-digit vs 13-digit Epoch timestamp bug.
1. Why Use Web Crypto API Over Math.random()
Math.random() is a non-cryptographic PRNG and should never be used for credentials or tokens. Browser Web Crypto APIs (crypto.getRandomValues and crypto.randomUUID) draw from OS-level CSPRNG entropy.
2. How Unique Is UUID v4?
RFC 4122 UUID v4 packs 122 random bits—roughly 5.3 × 10³⁶ possible values—making accidental collisions virtually impossible in distributed databases and microservices.
3. Seconds (10 Digits) vs. Milliseconds (13 Digits)
Mixing Unix seconds (used by JWT exp, Python time.time(), and POSIX APIs) with milliseconds (used by JavaScript Date.now() and Java) is a classic source of 1970/58000-year date bugs. Always check digit length when debugging timestamps.