Issue
Code backup
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
Reference in New Issue
Block a user