I am trying to check the strength of a password and I am having trouble validating that if the function has an empty argument, it should return “invalid” but I am getting “weak” instead.
function passwordStrength(password) {
let strengthCounter = 0;
for (const prop in regexObj) {
if (!regexObj[prop].regex.test(password) && (!Object.values(regexObj)[0].regex.test(password) || !Object.values(regexObj)[1].regex.test(password))) {
strengthCounter;
} else if (regexObj[prop].regex.test(password) && Object.values(regexObj)[1].regex.test(password)) {
strengthCounter++;
}
}
if (strengthCounter >= 6) return strengthStatusObj.strong;
if (strengthCounter >= 4) return strengthStatusObj.medium;
if (strengthCounter == 3) return strengthStatusObj.weak;
if (strengthCounter < 3) return strengthStatusObj.invalid;
}