JavaScript ci permette di generare password alfanumeriche casuali.
La soluzione รจ la seguente:
'use strict';
const random = {
choice(arr) {
const index = Math.floor(Math.random() * arr.length);
return arr[index] || '';
}
};
const createPassword = (length = 8) => {
const digits = '0123456789';
const upper = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
const lower = 'abcdefghijklmnopqrstuvwxyz';
const chars = digits + upper + lower;
const output = [];
for(let i = 0; i <= length; i++) {
output.push(random.choice(chars));
}
return output.join('');
};