Enrollment + almost all auth
This commit is contained in:
16
lib/pairingCode.ts
Normal file
16
lib/pairingCode.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { randomBytes } from "crypto";
|
||||
|
||||
const PAIRING_ALPHABET = "ABCDEFGHJKLMNPQRSTUVWXYZ23456789";
|
||||
|
||||
export function generatePairingCode(length = 5) {
|
||||
const bytes = randomBytes(length);
|
||||
let code = "";
|
||||
for (let i = 0; i < length; i += 1) {
|
||||
code += PAIRING_ALPHABET[bytes[i] % PAIRING_ALPHABET.length];
|
||||
}
|
||||
return code;
|
||||
}
|
||||
|
||||
export function normalizePairingCode(input: string) {
|
||||
return input.trim().toUpperCase().replace(/[^A-Z0-9]/g, "");
|
||||
}
|
||||
Reference in New Issue
Block a user