mirror of
1
2
Fork 0
ucaptcha/server/src/helpers/utils.ts

14 lines
350 B
TypeScript

import crypto from "crypto";
const alphabets = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
export function randomBytes(length: number) {
const bytes = crypto.randomBytes(length);
const chars = [];
for (let i = 0; i < length; i++) {
chars.push(alphabets[bytes[i] % alphabets.length]);
}
return chars.join("");
}