Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Changing the color of Text Caption using Java Script for Password Strength exercise.

New Here ,
Jul 24, 2017 Jul 24, 2017

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");
  }

76
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
no replies

Have something to add?

Join the conversation
Resources
Help resources