//长度不低于8位。
//包括大小写字母(A-Z和a-z)。
//包括特殊符号(!@#$%^&*()-_=+[]{};:,.<>?/)
function generatePassword() {
const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[]{};:,.<>?/';
let password = '';
for (let i = 0; i < 8; i++) {
const randomIndex = Math.floor(Math.random() * chars.length);
password += chars[randomIndex];
}
return password;
}
console.log(generatePassword());
标签:randomIndex,chars,生成器,密码,-_,password,Math
From: https://www.cnblogs.com/Sultan-ST/p/17727365.html