paralleldrive/cuid2

Allow removing ambiguous symbols as an initialization option

Extarys opened this issue · 2 comments

I'd like to use cuid2 to generate a row id and a shorter public id the user can easily say or write down without having to think about similar characters (0=>Oo, 1=>L i). We could implement this ourselves client side, but it adds a step, and then we need to think about not forgetting the conversion every time we read or write to the database.

I'm no big brain, I'm not sure which characters we can live with and which can be removed while maintaining a good level of entropy.

Are you open to add this as an option when initializing?

Cuid2 is focused pretty exclusively on secure, opaque id generation - which typically is not very compatible with ids short enough to type out conveniently by hand.

The default length is 24 - if you use less than 22, you're getting into dangerous brute-force territory for use cases like user ids, session tokens, etc.

Because convenient typing and security are at odds, I have no plans to add custom alphabets. If the custom alphabet feature is important to you, and security is less a concern, NanoId may be a better fit for your use-case. It supports custom lengths and custom alphabets.

🤦 Thanks! Why didn't I think of Nanoid for user readable ID in the first place...

I get your point, options like that can open a wormhole of bad practices and users badly implementing cuid.

For my usecase, an index on both the rowID (CUID2) and the TaskID (NanoID), should be sufficient. I'll do some tests.

Thanks again!