github.com/lunarobliq/gophish@v0.8.1-0.20230523153303-93511002234d/static/js/src/app/passwords.js (about)

     1  import zxcvbn from 'zxcvbn';
     2  
     3  const StrengthMapping = {
     4      0: {
     5          class: 'danger',
     6          width: '10%',
     7          status: 'Very Weak'
     8      },
     9      1: {
    10          class: 'danger',
    11          width: '25%',
    12          status: 'Very Weak'
    13      },
    14      2: {
    15          class: 'warning',
    16          width: '50%',
    17          status: 'Weak'
    18      },
    19      3: {
    20          class: 'success',
    21          width: '75%',
    22          status: 'Good'
    23      },
    24      4: {
    25          class: 'success',
    26          width: '100%',
    27          status: 'Very Good'
    28      }
    29  }
    30  
    31  const Progress = document.getElementById("password-strength-container")
    32  const ProgressBar = document.getElementById("password-strength-bar")
    33  const StrengthDescription = document.getElementById("password-strength-description")
    34  
    35  const updatePasswordStrength = (e) => {
    36      const candidate = e.target.value
    37      // If there is no password, clear out the progress bar
    38      if (!candidate) {
    39          ProgressBar.style.width = 0
    40          StrengthDescription.textContent = ""
    41          Progress.classList.add("hidden")
    42          return
    43      }
    44      const score = zxcvbn(candidate).score
    45      const evaluation = StrengthMapping[score]
    46      // Update the progress bar
    47      ProgressBar.classList = `progress-bar progress-bar-${evaluation.class}`
    48      ProgressBar.style.width = evaluation.width
    49      StrengthDescription.textContent = evaluation.status
    50      StrengthDescription.classList = `text-${evaluation.class}`
    51      Progress.classList.remove("hidden")
    52  }
    53  
    54  document.getElementById("password").addEventListener("input", updatePasswordStrength)