created at 2023/05/19 05:37:44
updated at 2023/07/25 12:08:40
JavaScript
function generatePassword(length) {
let charset =
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()_-+={}[]|\\:;\"'<>,.?/";
let password = "";
for (let i = 0; i < length; i++) {
let randomIndex = Math.floor(Math.random() * charset.length);
password += charset[randomIndex];
}
return password;
}
console.log(generatePassword());