Skip to main content

password_strength_checker 2.0.0 copy "password_strength_checker: ^2.0.0" to clipboard
password_strength_checker: ^2.0.0 copied to clipboard

Animated password strength bar, form validation with a minimum strength, 10k leaked password check and a secure password generator.

password_strength_checker

Pub version Pub points Monthly downloads CI License

Animated strength bar · Form validation · 10k leaked-password check · Secure generator
Zero dependencies. Fully customizable. Bring your own strength rules.


✨ Features #

📊 PasswordStrengthChecker An animated bar that follows any ValueListenable of strength. Theme-aware (light and dark) and accessible.
📝 PasswordStrengthFormChecker A drop-in Form field. It validates against a minimumStrengthRequired and can show a confirmation field and a generate button.
✅ PasswordRequirementsChecklist A live checklist that ticks each rule (length, lowercase, symbol…) as the user types. Bring your own rules and labels.
🛡️ isCommonPassword Checks a password against the 10,000 most common leaked passwords. The match is case-insensitive.
🔁 findWeakPatterns Detects repeats (aaaa), sequences (1234, abcd) and keyboard runs (qwer), which the default rating penalizes.
🎲 PasswordGenerator Generates passwords with Random.secure() and per-class minimums, skipping weak patterns.
🗝️ PassphraseGenerator Generates memorable passphrases from the EFF wordlist, with entropy reporting.
🎨 Custom strength Implement PasswordStrengthItem on your own enum to define your own levels, colors and rules.

🎬 Demo #

Form validation Strength bar Password generator

🚀 Getting started #

flutter pub add password_strength_checker
import 'package:password_strength_checker/password_strength_checker.dart';

Form field with validation #

The widget calculates the strength for you. The form is valid only when the password reaches minimumStrengthRequired.

Form(
  key: formKey,
  child: PasswordStrengthFormChecker<PasswordStrength>(
    minimumStrengthRequired: PasswordStrength.secure,
    strengthCalculator: (text) => PasswordStrength.calculate(text: text),
    needConfirmation: true, // optional confirmation field
    showGenerator: true,    // optional "Generate password" button
    requirements: PasswordRequirement.defaults, // optional live checklist
  ),
);

Pass controller, decoration, focusNode or autovalidateMode to tune the default field. For full control, use fieldBuilder to plug in your own field:

PasswordStrengthFormChecker<PasswordStrength>(
  minimumStrengthRequired: PasswordStrength.strong,
  strengthCalculator: (text) => PasswordStrength.calculate(text: text),
  fieldBuilder: (context, data) => MyFancyField(
    controller: data.controller,
    validator: data.validator,
  ),
);

➡️ Full example

Strength bar only #

final strength = ValueNotifier<PasswordStrength?>(null);

TextField(
  onChanged: (text) => strength.value = PasswordStrength.calculate(text: text),
);
PasswordStrengthChecker(strength: strength);

Use PasswordStrengthCheckerConfiguration to change the size, the border, the animation, the direction and the status widget.

➡️ Full example

Password generator #

const generator = PasswordGenerator(
  PasswordGeneratorConfiguration(length: 32, minUppercase: 8, minSpecial: 8),
);

final password = generator.generate();

➡️ Full example

Requirements checklist #

Show which rules the password already meets, inside the form with requirements: or anywhere with the standalone widget:

PasswordRequirementsChecklist(
  password: controller, // the TextEditingController of your field
  requirements: [
    PasswordRequirement.minLength(16, label: 'Almeno 16 caratteri'),
    PasswordRequirement.uppercase(label: 'Una lettera maiuscola'),
    PasswordRequirement.special(label: 'Un simbolo'),
    PasswordRequirement.noWeakPatterns(),
    PasswordRequirement('No spaces', (p) => p.isNotEmpty && !p.contains(' ')),
  ],
);

Passphrase generator #

const generator = PassphraseGenerator(
  PassphraseConfiguration(wordCount: 6, capitalize: true, includeNumber: true),
);

generator.generate();  // e.g. "Acid-Brook-Flint7-Jolly-Crate-Oasis"
generator.entropyBits; // ≈ 67.9

The default wordlist is the EFF Short Wordlist 1 (1,296 words, about 10.3 bits per word). Pass words: to use your own.

Leaked password check #

isCommonPassword('Password'); // true, case-insensitive
commonPasswords.length;       // 10000

📏 Default rules #

PasswordStrength.calculate checks the rules in this order:

Level Rule
alreadyExposed The password is in the 10k leaked list.
weak Fewer than 12 characters, or only 1 character class. Weak patterns (aaaa, 1234, qwer) count as 2 characters.
medium 2 character classes.
strong 3 character classes.
secure Lowercase + uppercase + digit + special character.

A special character is anything that is not a letter, a digit or whitespace, Unicode included (., +, €…). Accented letters such as à or Ç count as lowercase or uppercase letters.

🎨 Custom strength #

enum MyStrength implements PasswordStrengthItem {
  weak,
  medium,
  strong;

  @override
  Color get statusColor => switch (this) {
    weak => Colors.red,
    medium => Colors.orange,
    strong => Colors.green,
  };

  @override
  double get widthPerc => switch (this) {
    weak => 0.3,
    medium => 0.6,
    strong => 1.0,
  };

  @override
  Widget? get statusWidget => Text(name);

  static MyStrength? calculate(String text) {
    if (text.isEmpty) return null;
    if (isCommonPassword(text) || text.length < 6) return weak;
    return text.length < 10 ? medium : strong;
  }
}

PasswordStrengthFormChecker<MyStrength>(
  minimumStrengthRequired: MyStrength.medium,
  strengthCalculator: MyStrength.calculate,
);

The enum order is the strength order: a value declared later counts as stronger.

🔄 Migrating from 1.x #

1.x 2.0
onChanged: (p, notifier) => notifier.value = PasswordStrength.calculate(text: p) strengthCalculator: (p) => PasswordStrength.calculate(text: p)
textFormFieldConfiguration: TextFormFieldConfiguration(...) controller, decoration, focusNode, obscureText, autofillHints, autovalidateMode, or fieldBuilder
confirmationTextFormFieldConfiguration confirmationController, confirmationDecoration
onPasswordGenerated: (password, notifier) {} onPasswordGenerated: (password) {}. The strength updates automatically.
generateButtonSize (fixed 48 px ElevatedButton) generateButtonStyle. The button is now a FilledButton.tonal that stretches to the form width.
emptyTextErrorMessage: null to allow an empty password emptyTextErrorMessage is a non-null String, so an empty password is always invalid.
Default confirmation decoration had errorStyle: TextStyle(height: 0) Default decorations show the error text. Pass your own decoration and confirmationDecoration to hide it.
commonDictionary[text] == true isCommonPassword(text) or commonPasswords.contains(text)
PasswordGenerator.fromConfig(configuration: c) PasswordGenerator(c)
generate(printDebugInfo: true) Removed. It printed the password to the logs.
PasswordGeneratorConfiguration(numberOfShuffles: n) Removed. One shuffle with Random.secure() is enough.
specialChars: ['!', '@'] specialChars: '!@'
statusWidgetAlignment: MainAxisAlignment.start statusWidgetAlignment: AlignmentDirectional.centerStart
inactiveBorderColor: Colors.black (default) null by default, which follows the theme's outlineVariant.

Behavior change: any character that is not a letter, a digit or whitespace now counts as special, accented letters count as letters, the leaked-password check is case-insensitive, and weak patterns such as aaaa, 1234 or qwer count as only 2 characters toward the length. Some passwords can therefore get a different strength than in 1.x.

📄 Credits #

The passphrase wordlist is the EFF Short Wordlist 1 by the Electronic Frontier Foundation, licensed under CC BY 3.0.

🤝 Contributing #

Bug reports, feature requests and pull requests are welcome in the repository.

Contributors

Made with ❤️ by dariowskii

55
likes
150
points
11.9k
downloads
screenshot

Documentation

API reference

Publisher

verified publisherdariovarriale.dev

Weekly Downloads

Animated password strength bar, form validation with a minimum strength, 10k leaked password check and a secure password generator.

Repository (GitHub)
View/report issues

Topics

#password #password-strength #security #form #validation

License

MIT (license)

Dependencies

flutter

More

Packages that depend on password_strength_checker