feathers-authentication-management
Version:
Adds sign up verification, forgotten password reset, and other capabilities to local feathers-authentication
21 lines (16 loc) • 469 B
text/typescript
import { randomBytes } from './random-bytes';
import { randomDigits } from './random-digits';
export async function getShortToken (
len: number,
ifDigits: boolean
): Promise<string> {
if (ifDigits) {
return randomDigits(len);
}
const str1 = await randomBytes(Math.floor(len / 2) + 1);
let str = str1.substr(0, len);
if (str.match(/^[0-9]+$/)) { // tests will fail on all digits
str = `q${str.substr(1)}`; // shhhh, secret.
}
return str;
}