From 584d0092d8d145e889cb314ba67ffb14d3551778 Mon Sep 17 00:00:00 2001 From: Wolvan Date: Wed, 29 Dec 2021 14:13:35 +0100 Subject: [PATCH] Avoid ambigous characters in IDs The issue with ambigous characters is that they are hard to write when only seeing them, as one could confuse 0 for O with certain typefaces for example. Ambiguity is lessened by removing `Oo0Iil1` from the possible charset. In order to keep a big enough pool of IDs the ID length changed from 6 to 8 characters instead, which seems like an OK tradeoff. --- src/backend.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/backend.ts b/src/backend.ts index 9e23103..6eb3c37 100644 --- a/src/backend.ts +++ b/src/backend.ts @@ -17,7 +17,7 @@ type Poll = { creationTime: Date, }; -function randomString(length = 10, charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789") { +function randomString(length = 10, charset = "abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789") { let result = ""; for (let i = 0; i < length; i++) { result += charset.charAt(Math.floor(Math.random() * charset.length)); @@ -76,7 +76,7 @@ export default async function init(router: Router): Promise { const options = req.body.options; if (!Array.isArray(options) || options.filter(i => i).length < 2) return res.status(400).json({ error: "Options must be an array and have at least 2 entries" }); - let id = randomString(6); + let id = randomString(8); while (await polls.getItem(id)) id = randomString(6); await polls.setItem(id, {}); const dupeCheckMode = ["none", "ip", "cookie"].includes(req.body.dupeCheckMode) ? req.body.dupeCheckMode : "ip";