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
๐ 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.
Made with โค๏ธ by dariowskii
Libraries
- password_strength_checker
- Password strength bar, form validation, leaked password check and secure password generator for Flutter.