4 ms·
Thanks for all the improvement suggestions! Taking them into account, the `makeSlug` function becomes: function makeSlug(length: number): string {
by strnisa 2y ago
Thanks for all the improvement suggestions! Taking them into account, the `makeSlug` function becomes:
function makeSlug(length: number): string {
const alphabet = "0123456789abcdefghjkmnpqrstvwxyz";
let result = "";
for (let i = 0; i < length; i++) {
result += alphabet[crypto.randomInt(alphabet.length)];
}
return result;
}
- biztos 2y agoI think that 0 and 1 are likely to cause problems when customers end up reading their "user ID" back to your employees in Customer Support Country over the phone. "It's one-three-oh-dee-ee-el. Yes, I'm sure, EL as in elephant."
- jagged-chisel 2y agoOne can convert those to the correct characters. Since “oh” and “el” are excluded from the alphabetic range, they become “zero” and “one” - deciding whether that is done in software for the help desk, or in the brain of the help desk staff is left as an exercise to management.
- smaudet 2y agoI wonder if Unicode could be used to alter the characters such that these mistakes would be less possible, e.g. using ⓪.
- fhars 2y agoThat is "AT", isn't it? (No, it isn't, if you look closely enough.)
- smaudet 2y agoYeah...what I'd really like to do would be to give a character a "natural" background color, e.g. Then its simple for support to say "red is one, green is ell". But you can't just add a color to a character, because copy paste/rich formatting don't work everywhere, or even transfer well... Alternatively, if you use ⓪ and ⒈ it matters less if the user says "at" or "zero", and more that they didn't say "oh" or "one".
- Piskvorrr 2y agoIt's obviously a �. Or perhaps a □ . Maybe an ¾, on odd Wednesdays? (Unicode has its strengths. Making up replacement characters isn't one.)
- codr7 2y agoI happen to know that the biggest ski resort reservation system in Scandinavia contains a function called MaybeOnATuesday(), but to my knowledge it's never called.
- WorldMaker 2y agoIf you are trying for URL safe, Unicode is problematic because of Punycode conversions and differing browser behavior with Unicode URLs. (Some browsers always show Unicode as Unicode in URLs. Some browsers always show Unicode as Punycode in URLs. Some browsers switch between the two based on a huge number of variables such as gTLD, user preference, phase of the moon, etc.)
- gvx 2y agoAnything that needs to be read over the phone should probably be written out using something like the NATO phonetic alphabet, split into smaller chunks if needed: "The code? It's kilo eight niner; one three mike; delta echo lima."
- 8372049 2y agoHaving come from a military background where using that is second nature, I'm constantly surprised how rarely I meet civilians who understand it effortlessly. When picking up a package I say "the code is Oscar Foxtrot three-fife" and you see the person processing for a long time to extract the first letter of the word. I've started saying "OF, that's Oscar Foxtrot, 3-5" to help them out. In other words, asking a customer/consumer to be able to recite something in phonetics is not realistic in most cases. Fortunately the code already takes this into consideration and removes ambiguous characters.
- hprotagonist 2y agodigikey phone personnel all speak NATO. it’s wonderful.
- hobs 2y agoFirst thing I drilled into Apple phone support folks.
- mannykannot 2y agoMy experience in the USA is that if I don't include the phrase "as in" (as in "X as in Xray") most people still will not realize what I am doing (the alternative "for" can be confused with the digit.) I also ask them to check my readback of key information they have given me and vice-versa; usually that works well.
- gbacon 2y ago*tree :-)
- 8372049 2y agoi, L and o are left out of the alphabet in the snippet, so there's not really any ambiguity.
- jgalt212 2y agoOr just drop the L and O, like CUSIP does.
- kstenerud 2y agoI developed safe32 for this reason. https://github.com/kstenerud/safe-encoding/blob/master/safe32-specification.md https://github.com/kstenerud/safe-encoding/blob/master/safe3... Notably, confusable characters are interchangeable when being ingested (although a machine encoder MUST always produce canonical output). https://github.com/kstenerud/safe-encoding/blob/master/safe32-specification.md#alphabet https://github.com/kstenerud/safe-encoding/blob/master/safe3... So a user can confuse 1 for l, 0 for o, I for l, u for v, uppercase, lowercase etc, or the agent can say any of those over the phone, and it won't matter.
- vanderZwan 2y agoOh that looks well-thought out and is probably the sanest way to solve this particular problem! It's obvious why the safe64/safe80/safe85 cannot do this, but is there a reason why the safe16 version doesn't have the same features?
- kstenerud 2y agoOh whoops that's an oversight! I'll fix that up tonight.
- what 2y agoIsn’t this just crockford encoding?
- kstenerud 2y agoEvery base-32 style encoding is Crockford at the core. The difference is in the alphabet, and also whether it requires padding or not (safe32 does not). Crockford also incorporates error correction, which is unnecessary in modern systems since the underlying protocols do that already.
- ss64 2y agoAnother approach is using base31 with all vowels removed https://ss64.com/ps/syntax-base31.html https://ss64.com/ps/syntax-base31.html
- inopinatus 2y agoMy favourite ambiguous readback is to say "M for Movember". I have a note from a few years ago that 367CDFGHJKMNPRTWX may be a sufficiently unambiguous alphabet. Drop the one you like the least (probably N) to obtain a faux hex encoding.
- kodisha 2y agoOr, just use cuid2 [1] + prefix. [1] https://github.com/paralleldrive/cuid2 https://github.com/paralleldrive/cuid2
- fnordsensei 2y agoOne thing I’ve been looking for in an ID generator is a way to supply a blocklist. There are a number of character combinations I’d like to avoid in IDs, because they might be offensive or get stuck in filters when copy-pasted (e.g. in a URI). This can be solved in user space by regenerating if the character sequences are detected, but this a) skews the distribution, and b) potentially takes time, especially when the ID generator is made to not be “too fast”. I want to generate a single ID that passes the blocklist in a timeframe that is not too fast, if that makes sense. Is there an ID generator that takes this into consideration?
- ceejayoz 2y agoJust take out the vowels and numbers that can look like vowels. Nixing 0 means no b00bs IDs, and avoids 0/O; I usually take out 1/I as well.
- fnordsensei 2y agoThat goes some of the way, but I can think of a few problematic sequences that are only consonants and/or numbers.
- ceejayoz 2y agoI like to nix vowels and things that look like them, i.e. 0, to avoid random b00bs sort of tokens.
- travisgriggs 2y agoLet’s not get sexist here! It also avoids random d1ck and c0ck sorts of tokens.
- madcaptenor 2y agoSure, but I can see people still getting offended if "fck" showed up.
- Tangurena2 2y agoThis is why an open source project is now "CK Editor". It was the author's initials, but too many people saw an extra vowel in the name of the project. https://en.wikipedia.org/wiki/CKEditor https://en.wikipedia.org/wiki/CKEditor
- inopinatus 2y agoHaving a zero in your alphabet can be problematic, because leading zeros are often stripped (e.g. Excel notoriously mangles phone numbers thinking they are integers). Multiple calls to a randomness generator can be expensive, and a waste of entropy; production-scale random string generators should still respect this and ask for a block of bytes, then encode them, but with bias correction. You're off the hook in this case, I think node's implementation of randomInt is doing exactly that for you and conserving remaining entropy in a cache.