var strong = /^[a-zA-Z\d\W_]*(?=[a-zA-Z\d\W_]{6,})
(((?=[a-zA-Z\d\W_]*[A-Z])(?=[a-zA-Z\d\W_]*[\d]))
|((?=[a-zA-Z\d\W_]*[A-Z])(?=[a-zA-Z\d\W_]*[\W_]))
|((?=[a-zA-Z\d\W_]*[\d])(?=[a-zA-Z\d\W_]*[\W_])))
[a-zA-Z\d\W_]*$/;
while (true) {
var password = prompt("Enter password", "");
if (password == null) {
alert("Error: Unable to read password, Refresh the page to try again!");
break;
}
else if (password.length < 7)
alert("Password must be longer than " + (password.length + 1) + " characters");
else if (!strong.test(password))
alert("You must enter a stronger passoword, make sure you enter a strong password");
else
alert(GenerateRandomError(password));
}
function GenerateRandomError(password) {
var error = Math.floor(Math.random() * 1)
switch (error) {
case 0:
return InvalidCharInPosError(password);
default:
}
}
function GetPosString(position) {
switch (position) {
case 0:
return "1st";
case 1:
return "2nd";
case 2:
return "3rd"
default:
return (position + 1) + "th";
}
}
function InvalidCharInPosError(password) {
var pos = Math.floor(Math.random() * password.length);
return "The character \'" + password.substr(pos, 1)
+ "\' is not supported in the " + GetPosString(pos) + "position";
}
</script>