Files
kavehhn f04c797be6 Initial commit: teaching institution management API.
Express/MongoDB backend with JWT auth, RBAC, S3 uploads, notifications, and scheduled jobs.
2026-08-09 04:18:08 +02:00

28 lines
708 B
JavaScript

// /utils/credentials.js
'use strict';
const crypto = require('crypto');
const LETTERS = 'abcdefghijkmnpqrstuvwxyz';
const DIGITS = '23456789';
const randomFrom = (alphabet, length) => {
let out = '';
const bytes = crypto.randomBytes(length);
for (let i = 0; i < length; i += 1) {
out += alphabet[bytes[i] % alphabet.length];
}
return out;
};
/** Simple password: exactly 2 English letters + 4 digits (e.g. kx4821) */
const generateSimplePassword = () => `${randomFrom(LETTERS, 2)}${randomFrom(DIGITS, 4)}`;
/** Random username: u + 6 digits (e.g. u482910) */
const generateUsername = () => `u${randomFrom(DIGITS, 6)}`;
module.exports = {
generateSimplePassword,
generateUsername,
};