Password strength

A meter under a new-password field that says how strong the password is, in words, as it is typed. Paired with reveal on input, which adds a button to show the password.

Password strength

Needs Alpine and the package's script. See getting started.

Use it

<x-ds::input
    type="password"
    id="password"
    name="password"
    label="New password"
    autocomplete="new-password"
    help="At least 8 characters."
    :reveal="true"
    :error="$errors->first('password')"
/>
<x-ds::password-strength for="password" />

The meter is bound to the field by for, the field's id, the way a label is. Give the input an id so there is something to point at.

It is a hint, not a security control

The score is a small heuristic of the package's own, run in the browser: length first, then the mix of character kinds, minus runs like aaaa or 1234 and minus the commonest passwords dressed up with capitals and symbols (P@ssw0rd! is Weak). It knows nothing about the person, the site, or the breach lists a real checker consults, and anyone can switch it off in their browser.

So: your server's rules decide what is accepted. Laravel's Password::min(8)->uncompromised() checks against known breaches, which this cannot. Use the meter to help someone choose before they press Save, never to decide whether they may.

What it does not see, so a password can score Strong and still be weak:

  • Words and names. Only a short list of the commonest passwords is known, in English. Correcthorsebattery1! and a pet's name with a year score on length and mix alone.
  • Dates and numbers that mean something: birthdays, phone numbers, years.
  • The person and the site: their email, their name, the product's name.
  • Breaches. No list of leaked passwords beyond that short one.
  • Other alphabets. Letters outside A to Z count as symbols, so a long password in Hindi or Greek scores on length and that one kind.

Runs it does catch: abcd, 1234, aaaa and the keyboard rows (qwerty, asdf, zxcv), forwards and back.

Props

PropTypeDefaultWhat it does
forstringrequiredThe id of the password input it measures.
minLengthint8Shorter than this, a password is Weak whatever else it has. Match your server's rule.
labelsarray['Weak', 'Fair', 'Good', 'Strong']The four level names, weakest first. Pass fewer to replace only the first ones.

The levels

LevelShown as
Nothing typedFour empty bars, no words
WeakOne bar, danger
FairTwo bars, warning
GoodThree bars, success
StrongFour bars, success

The level is never colour alone: the number of bars lit and the word under them say it too.

Reveal

reveal on ds::input adds a button inside the field that shows the password as text and hides it again. It works on any type="password" input, with or without the meter.

<x-ds::input type="password" name="password" label="Password" autocomplete="current-password" :reveal="true" />
  • The button is named "Show password" and says whether the password is showing with aria-pressed. The name does not change; the eye icon does.
  • Pressing it keeps focus and the caret in the field, so someone checking what they typed can carry on typing.
  • It never submits the form, and when the form submits the field goes back to hidden, so the browser offers to save a password rather than a line of text.

reveal only applies to type="password". On any other type it is ignored.

Accessibility

  • The level is spoken through a polite live region, as a whole sentence: "Password strength: Good". It speaks when the level changes, not on every key.
  • The bars are decoration (aria-hidden); the words carry the meaning.
  • The reveal is a toggle button with a fixed name and aria-pressed, as the WAI-ARIA pattern for toggle buttons asks. A name that also flipped to "Hide password" would be read as "Hide password, pressed": two answers to one question.

Don't

  • Don't block a submit on the meter. See above.
  • Don't use it on a sign-in form. Measuring a password someone already has tells them nothing and tells anyone watching the screen something.
  • Don't put the rules only in the meter. Say them in the field's help ("At least 8 characters"), where they are read before typing, not after.

More in specs/password-strength.md.


From the package repo: edit this page on GitHub.

Was this page helpful?