JS随机⽣成密码(⾄少包含⼀个⼤写字母,⼩写字母,数字,
特殊符号)
玩小女孩的经典说说之所以选择数组是因为会在数组内随机插⼊⼤⼩写/数字/特殊符号
// Random user password
function randomPassword(length) {
length = Number(length)
// Limit length
if (length < 6) {
length = 6
} else if (length > 16) {
length = 16
}
古文名句let passwordArray = ['ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz', '1234567890', '!@#$%&*()'];
var password = [];
let n = 0;
for (let i = 0; i < length; i++) {
// If password length less than 9, all value random
if ( password.length < (length - 4) ) {
以幸福为话题作文// Get random passwordArray index
let arrayRandom = Math.floor(Math.random() * 4);
// Get password array value
let passwordItem = passwordArray[arrayRandom];
综合管理员岗位职责// Get password array value random index梦见捡钱是什么意思?
// Get random real value
let item = passwordItem[Math.floor(Math.random() * passwordItem.length)];
password.push(item);
} else {
// If password large then 9, lastest 4 password will push in according to the random password index
// Get the array values sequentially
let newItem = passwordArray[n];
let lastItem = newItem[Math.floor(Math.random() * newItem.length)];
// Get array splice index
let spliceIndex = Math.floor(Math.random() * password.length);
新股申购时间
password.splice(spliceIndex, 0, lastItem);
n++
}
}
return password.join("");
}
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论