Files
console-dev/app/lib/password-2.js
T

27 lines
886 B
JavaScript

/**
* 生成便于辨认的随机密码建议:至少含小写、大写和数字各一位,排除易混字符。
* 现有实现使用 Math.random(非密码学随机源),不能当作高强度密钥/令牌生成器;
* 即使 e 小于 3,三个必选字符也会保留。此处注释如实说明现有行为,不改变协议。
*/
function e(e = 12) {
let t = (e) => e[Math.floor(Math.random() * e.length)],
n = [
t(`abcdefghjkmnpqrstuvwxyz`),
t(`ABCDEFGHJKMNPQRSTUVWXYZ`),
t(`23456789`),
],
r = Array.from(
{
length: Math.max(0, e - n.length),
},
() => t(`abcdefghjkmnpqrstuvwxyzABCDEFGHJKMNPQRSTUVWXYZ23456789`),
),
i = [...n, ...r];
for (let e = i.length - 1; e > 0; e--) {
let t = Math.floor(Math.random() * (e + 1));
[i[e], i[t]] = [i[t], i[e]];
}
return i.join(``);
}
export { e as t };