Back to project
JavaScript

Interactive JavaScript Logic

This part updates the strength meter, switches hashing modes, and keeps the page interactive as you type.

pwInput.addEventListener('input', analyze);
hashInput.addEventListener('input', doHash);

function analyze() {
  const pw = pwInput.value;
  const cLen = pw.length >= 8;
  const cUp = /[A-Z]/.test(pw);
  const cLow = /[a-z]/.test(pw);
  const cNum = /[0-9]/.test(pw);
  const cSym = /[^a-zA-Z0-9]/.test(pw);

  const score = [cLen, cUp, cLow, cNum, cSym].filter(Boolean).length;
  const level = score <= 2 ? 'Weak' : score <= 4 ? 'Good' : 'Strong';

  document.getElementById('strength-lbl').textContent = level;
}