DEV Community

Arhan Khan
Arhan Khan

Posted on

Build a Password Strength Checker App with JavaScript

A password strength checker is a small app that tells a user how strong their password is, as they type. It is a great beginner project because it teaches you input events, string checks, and live UI updates — and the result is something every website actually needs.

How does it work? The app listens to every keystroke in a password field, runs a few simple checks — length, uppercase, lowercase, numbers, symbols — and shows a strength meter and a checklist that updates in real time.

<!-- index.html -->
<input type="password" id="password" placeholder="Type a password..." />
<div id="meter"><div id="bar"></div></div>
<p id="label">Start typing to check strength</p>
<ul id="checks">
  <li id="c-length">At least 8 characters</li>
  <li id="c-upper">An uppercase letter</li>
  <li id="c-lower">A lowercase letter</li>
  <li id="c-number">A number</li>
  <li id="c-symbol">A symbol (!@#$...)</li>
</ul>
Enter fullscreen mode Exit fullscreen mode
// script.js — score the password on every keystroke
const input = document.getElementById('password');
const bar = document.getElementById('bar');
const label = document.getElementById('label');

input.addEventListener('input', () => {
  const value = input.value;

  const checks = {
    'c-length': value.length >= 8,
    'c-upper': /[A-Z]/.test(value),
    'c-lower': /[a-z]/.test(value),
    'c-number': /[0-9]/.test(value),
    'c-symbol': /[^A-Za-z0-9]/.test(value),
  };

  let score = 0;
  for (const [id, passed] of Object.entries(checks)) {
    document.getElementById(id).style.color = passed ? 'green' : 'gray';
    if (passed) score++;
  }

  const levels = ['Very weak', 'Weak', 'Okay', 'Good', 'Strong', 'Excellent'];
  const colors = ['#e11d48', '#f97316', '#eab308', '#84cc16', '#22c55e', '#059669'];
  bar.style.width = (score / 5) * 100 + '%';
  bar.style.background = colors[score];
  label.textContent = value ? levels[score] : 'Start typing to check strength';
});
Enter fullscreen mode Exit fullscreen mode
/* style.css — the strength meter */
#meter {
  height: 8px;
  background: #e5e7eb;
  border-radius: 4px;
  margin: 12px 0;
  overflow: hidden;
}
#bar {
  height: 100%;
  width: 0;
  transition: width 0.2s ease;
}
Enter fullscreen mode Exit fullscreen mode

This project teaches you a pattern you will use everywhere: listen for input, compute a result, and update the page immediately. The same pattern powers live search, form validation, and character counters.

The limits are worth knowing. A strength meter is a guide, not a guarantee — a long password of random words can be strong even without symbols, and a short password with all four character types can still be weak. For real apps, use a proper strength library like zxcvbn instead of hand-rolled rules.

Start today: build the page above, type a few passwords, and watch the meter move. Then add one extra feature — a button that generates a strong password for you.

Top comments (0)