368d6fafea
Code backup
13 lines
519 B
JavaScript
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;
|
|
} |