Files
VSC/JavaScript/000 - FunctionRepos.js
claudio 368d6fafea Issue
Code backup
2026-05-10 16:59:01 +02:00

13 lines
519 B
JavaScript

function generatePassword(length) {
const crypto = window.crypto || window.Crypto;
if (typeof crypto === 'undefined') {
throw new Error('Crypto API is not supported. Please upgrade your web browser');
}
const charset = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz!@#-+()*';
const indexes = crypto.getRandomValues(new Uint32Array(length));
let secret = '';
for (const index of indexes) {
secret += charset[index % charset.length];
}
return secret;
}