题解 | #密码强度等级#
密码强度等级
https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361
const rl = require("readline").createInterface({ input: process.stdin });
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
while ((line = await readline())) {
let tokens = line;
let count = 0;
// 长度
if (tokens.length <= 4) {
count = count + 5;
} else if (tokens.length >= 5 && tokens.length <= 7) {
count = count + 10;
} else {
count = count + 25;
}
// 字母
let reg1 = /[a-z]/g.test(tokens);
let reg2 = /[A-Z]/g.test(tokens);
if ((reg1 && !reg2) || (!reg1 && reg2)) {
count = count + 10;
} else if (reg1 && reg2) {
count = count + 20;
}
// 数字
let reg3 = tokens.match(/[0-9]/g)?tokens.match(/[0-9]/g).length:0;
if (reg3 == 1) {
count = count + 10;
} else if (reg3 > 1) {
count = count + 20;
}
// 符号
let reg4 = tokens.match(
/[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~]/g
)?tokens.match(
/[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~]/g
).length:0;
if (reg4 == 1) {
count = count + 10;
} else if (reg4 > 1) {
count = count + 25;
}
// 奖励
if (reg1 && reg2 && reg3 > 0 && reg4 > 0) {
count = count + 5;
} else if ((reg1 || reg2) && reg3 > 0 && reg4 > 0) {
count = count + 3;
} else if ((reg1 || reg2) && reg3 > 0) {
count = count + 2;
}
switch (true) {
case count >= 90:
console.log('VERY_SECURE');
break;
case count >= 80:
console.log('SECURE');
break;
case count >= 70:
console.log('VERY_STRONG');
break;
case count >= 60:
console.log('STRONG');
break;
case count >= 50:
console.log('AVERAGE');
break;
case count >= 25:
console.log('WEAK');
break;
case count >= 0:
console.log('VERY_WEAK');
break;
}
}
})();
var iter = rl[Symbol.asyncIterator]();
const readline = async () => (await iter.next()).value;
void (async function () {
// Write your code here
while ((line = await readline())) {
let tokens = line;
let count = 0;
// 长度
if (tokens.length <= 4) {
count = count + 5;
} else if (tokens.length >= 5 && tokens.length <= 7) {
count = count + 10;
} else {
count = count + 25;
}
// 字母
let reg1 = /[a-z]/g.test(tokens);
let reg2 = /[A-Z]/g.test(tokens);
if ((reg1 && !reg2) || (!reg1 && reg2)) {
count = count + 10;
} else if (reg1 && reg2) {
count = count + 20;
}
// 数字
let reg3 = tokens.match(/[0-9]/g)?tokens.match(/[0-9]/g).length:0;
if (reg3 == 1) {
count = count + 10;
} else if (reg3 > 1) {
count = count + 20;
}
// 符号
let reg4 = tokens.match(
/[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~]/g
)?tokens.match(
/[\!\"\#\$\%\&\'\(\)\*\+\,\-\.\/\:\;\<\=\>\?\@\[\\\]\^\_\`\{\|\}\~]/g
).length:0;
if (reg4 == 1) {
count = count + 10;
} else if (reg4 > 1) {
count = count + 25;
}
// 奖励
if (reg1 && reg2 && reg3 > 0 && reg4 > 0) {
count = count + 5;
} else if ((reg1 || reg2) && reg3 > 0 && reg4 > 0) {
count = count + 3;
} else if ((reg1 || reg2) && reg3 > 0) {
count = count + 2;
}
switch (true) {
case count >= 90:
console.log('VERY_SECURE');
break;
case count >= 80:
console.log('SECURE');
break;
case count >= 70:
console.log('VERY_STRONG');
break;
case count >= 60:
console.log('STRONG');
break;
case count >= 50:
console.log('AVERAGE');
break;
case count >= 25:
console.log('WEAK');
break;
case count >= 0:
console.log('VERY_WEAK');
break;
}
}
})();