Copy link to clipboard
Copied
I don't know if this has already been asked and answered. But I'm developing lesson on Information security and I'm testing the staff's ability to compose a strong password. I have a text entry box and I wrote a javascript with several long Regex validation statements to test if the entry conformed to a strong password and attached my script to a button. It seems to work. However, I would like the feedback caption to not only state whether the password is Strong, Good or Weak.. I would also like it to change to Green, Yellow or Red as well. Can I do that is in JavaScript?
Below is the script I wrote. It works.
var stringpass= window.cpAPIInterface.getVariableValue("passwordinput");
var strongRegex = new RegExp("^(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[!@#\$%\^&\*])(?=.{8,})");
var mediumRegex = new RegExp("^(((?=.*[a-z])(?=.*[A-Z]))|((?=.*[a-z])(?=.*[0-9]))|((?=.*[A-Z])(?=.*[0-9])))(?=.{6,})");
if (strongRegex.test(stringpass))
{
window.cpAPIInterface.setVariableValue("passwordstrength","Strong");
}
else if(mediumRegex.test(stringpass))
{
window.cpAPIInterface.setVariableValue("passwordstrength" , "Good");
}
else
{
window.cpAPIInterface.setVariableValue("passwordstrength" , "Weak");
}
Have something to add?