{"success":true,"name":"generate-ids-that-cannot-collide-or-be-guessed","description":"Creating unique identifiers for records, files, or sessions in code.","category":"ai-brimind","path":"ai-brimind/generate-ids-that-cannot-collide-or-be-guessed/SKILL.md","file":"SKILL.md","content":"---\nname: generate-ids-that-cannot-collide-or-be-guessed\ndescription: \"Creating unique identifiers for records, files, or sessions in code.\"\n---\n\n# Generate IDs That Cannot Collide or Be Guessed\n\n## When to use\nCode generates its own IDs (timestamps, counters, Math.random) instead of using database auto-IDs or proper UUID generation.\n\n## Example request\nDate.now() as an ID → two records created in the same millisecond collide and one overwrites the other — timestamp is not unique. Math.random() for session tokens → it's predictable, not cryptographic; tokens can be guessed — wrong randomness for security. Sequential IDs exposed in URLs (/user/1042) → anyone enumerates all users by counting — guessable identifier as access.\n\n## Instructions\nAct like a developer who matches the ID mechanism to what the ID must guarantee. Three cases: (1) DATABASE records — use the database's own mechanism (auto-increment, ObjectId, uuid default); don't reinvent uniqueness the storage layer already guarantees; never Date.now() or counters in app code, which collide under concurrency and multiple processes; (2) SECURITY tokens (sessions, reset links, API keys) — must be unguessable: use the crypto source (crypto.randomUUID(), crypto.randomBytes), never Math.random(), which is statistically fine and cryptographically worthless; length matters — short tokens are brute-forceable; (3) EXPOSED identifiers — anything in URLs or APIs where enumeration would leak data (user profiles, orders, uploaded files) should be non-sequential (UUID or random string), OR sequential-but-authorized: every access checks ownership regardless — obscurity of the ID is a bonus layer, never the access control itself. Also plan human needs: if support must read IDs aloud, a short-code alongside the UUID beats making the primary key friendly. Only proceed once each ID in the feature is labeled with its case and its generator matches.\n\n## Metadata\n- role: developer\n- level: tactical\n- places: vibeCoding\n- origin: ai.brimind.pro skill #1178\n","linked_files":[],"origin":"ai.brimind.pro","owner_id":null,"source":"router"}