pwstrength.tpl 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <br />
  2. <div class="progress mb-3" id="passwordStrengthBar">
  3. <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
  4. <span class="sr-only">{lang key='pwstrengthrating'}: 0%</span>
  5. </div>
  6. </div>
  7. {if file_exists("templates/$template/includes/alert.tpl")}
  8. {include file="$template/includes/alert.tpl" type="info" msg="<small><i class='fa fa-info-circle fa-fw'></i> {lang key='passwordtips'}</small>"}
  9. {elseif file_exists("templates/six/includes/alert.tpl")}
  10. {include file="six/includes/alert.tpl" type="info" msg="<small><i class='fa fa-info-circle fa-fw'></i> {lang key='passwordtips'}</small>"}
  11. {/if}
  12. <script>
  13. jQuery("#inputNewPassword1").keyup(function() {
  14. var pwStrengthErrorThreshold = {if isset($pwStrengthErrorThreshold)}{$pwStrengthErrorThreshold}{else}50{/if},
  15. pwStrengthWarningThreshold = {if isset($pwStrengthWarningThreshold)}{$pwStrengthWarningThreshold}{else}75{/if},
  16. progressBar = jQuery("#passwordStrengthBar .progress-bar"),
  17. pw = jQuery("#inputNewPassword1").val(),
  18. pwlength = (pw.length);
  19. if (pwlength > 5) {
  20. pwlength = 5;
  21. }
  22. var numnumeric = pw.replace(/[0-9]/g,""),
  23. numeric = (pw.length - numnumeric.length);
  24. if (numeric > 3) {
  25. numeric = 3;
  26. }
  27. var symbols = pw.replace(/\W/g,""),
  28. numsymbols = (pw.length-symbols.length);
  29. if (numsymbols > 3) {
  30. numsymbols = 3;
  31. }
  32. var numupper = pw.replace(/[A-Z]/g,""),
  33. upper = (pw.length - numupper.length);
  34. if (upper > 3) {
  35. upper = 3;
  36. }
  37. var pwstrength = ((pwlength * 10) - 20) + (numeric * 10) + (numsymbols * 15) + (upper * 10);
  38. if (pwstrength < 0) {
  39. pwstrength = 0;
  40. }
  41. if (pwstrength > 100) {
  42. pwstrength = 100;
  43. }
  44. jQuery(this).removeClass('is-invalid is-warning is-valid');
  45. progressBar.removeClass("bg-danger bg-warning bg-success").css("width", pwstrength + "%").attr('aria-valuenow', pwstrength);
  46. jQuery("#passwordStrengthBar .progress-bar .sr-only").html('{lang|addslashes key='pwstrengthrating'}: ' + pwstrength + '%');
  47. if (pwstrength < pwStrengthErrorThreshold) {
  48. jQuery(this).addClass('is-invalid');
  49. progressBar.addClass("bg-danger");
  50. } else if (pwstrength < pwStrengthWarningThreshold) {
  51. jQuery(this).addClass('is-warning');
  52. progressBar.addClass("bg-warning");
  53. } else {
  54. jQuery(this).addClass('is-valid');
  55. progressBar.addClass("bg-success");
  56. }
  57. validatePassword2();
  58. });
  59. function validatePassword2() {
  60. var password1 = jQuery("#inputNewPassword1").val(),
  61. password2Input = jQuery("#inputNewPassword2"),
  62. password2 = password2Input.val();
  63. if (password2 && password1 !== password2) {
  64. password2Input.removeClass('is-valid')
  65. .addClass('is-invalid');
  66. jQuery("#inputNewPassword2Msg").html(
  67. '<p class="form-text text-muted" id="nonMatchingPasswordResult">{"{lang key='pwdoesnotmatch'}"|escape}</p>'
  68. );
  69. {if !isset($noDisable)}
  70. jQuery('input[type="submit"]').attr('disabled', 'disabled');
  71. {/if}
  72. } else {
  73. if (password2) {
  74. password2Input.removeClass('is-invalid')
  75. .addClass('is-valid');
  76. {if !isset($noDisable)}jQuery('.primary-content input[type="submit"]').removeAttr('disabled');{/if}
  77. } else {
  78. password2Input.removeClass('is-valid is-invalid');
  79. }
  80. jQuery("#inputNewPassword2Msg").html('');
  81. }
  82. }
  83. jQuery(document).ready(function() {
  84. {if !isset($noDisable)}
  85. jQuery('.using-password-strength input[type="submit"]').attr('disabled', 'disabled');
  86. {/if}
  87. jQuery("#inputNewPassword2").keyup(function() {
  88. validatePassword2();
  89. });
  90. });
  91. </script>