SPB Git

Repository Public

codes.ts 2.2 KB 52 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : Chat SPBoucher AI8 * File             : src/lib/auth/codes.ts9 * Module           : lib10 * Repository       : https://git.spboucher.ai/chat-spboucher-ai11 * Project Website  : https://chat.spboucher.ai12 * Created          : 2026-11-1713 * Last Modified    : 2026-11-1714 *15 * Author           : Simon-Pierre Boucher16 * Position         : Professor of Finance17 * Institution      : Université du Québec en Outaouais (UQO)18 * Organization     : SP Boucher19 * Website          : https://spboucher.ai20 * Git              : https://git.spboucher.ai21 *22 * Preferred Contact: contact@spboucher.ai23 * Development      : dev@spboucher.ai24 * Support          : support@spboucher.ai25 * Security/Admin   : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License          : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243import { randomInt } from "node:crypto";4445/** One-time setup codes (bootstrap, recovery): pure helpers, no database access. */46const ALPHABET = "0123456789ABCDEFGHJKMNPQRSTVWXYZ"; // Crockford base32: no I, L, O, U47export function newCode(groups = 5): string {48  return Array.from({ length: groups }, () => Array.from({ length: 4 }, () => ALPHABET[randomInt(32)]).join("")).join("-");49}50/** Typing tolerance: case, spaces, dashes, and the look-alike letters Crockford defines. */51export const normalizeCode = (c: string) => c.toUpperCase().replace(/[^0-9A-Z]/g, "").replace(/[IL]/g, "1").replace(/O/g, "0").replace(/U/g, "V");52
Files main
Menu

Theme