sp_Showrav

password strength

Aug 1st, 2021 (edited)
1,210
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script language="javascript">
  2.     function passwordChanged() {
  3.         var strength = document.getElementById('strength');
  4.         var strongRegex = new RegExp("^(?=.{14,})(?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*\\W).*$", "g");
  5.         var mediumRegex = new RegExp("^(?=.{10,})(((?=.*[A-Z])(?=.*[a-z]))|((?=.*[A-Z])(?=.*[0-9]))|((?=.*[a-z])(?=.*[0-9]))).*$", "g");
  6.         var enoughRegex = new RegExp("(?=.{8,}).*", "g");
  7.         var pwd = document.getElementById("password");
  8.         if (pwd.value.length == 0) {
  9.             strength.innerHTML = 'Type Password';
  10.         } else if (false == enoughRegex.test(pwd.value)) {
  11.             strength.innerHTML = 'More Characters';
  12.         } else if (strongRegex.test(pwd.value)) {
  13.             strength.innerHTML = '<span style="color:green">Strong!</span>';
  14.         } else if (mediumRegex.test(pwd.value)) {
  15.             strength.innerHTML = '<span style="color:orange">Medium!</span>';
  16.         } else {
  17.             strength.innerHTML = '<span style="color:red">Weak!</span>';
  18.         }
  19.     }
  20. </script>
  21. <input name="password" id="password" type="text" size="15" maxlength="100" onkeyup="return passwordChanged();" />
  22. <span id="strength">Type Password</span>
  23.  
  24. https://martech.zone/javascript-password-strength/
RAW Paste Data