flutter_password_scoring 0.0.2+3
flutter_password_scoring: ^0.0.2+3 copied to clipboard
Helper library to score password strength with `dart_zxcvbn` and provide suggestions for improvement.
flutter_password_scoring #
❗ THIS PACKAGE IS STILL WORK IN PROGRESS ❗
Description #
The primary goal of this package is to support dart_zxcvbn
in Flutter.
To achieve this and, as much as possible, not block the main thread and avoid
dropped frames, we create an Isolate
in which the dart_zxcvbn
library is
initialized and where further user password evaluations take place. Responses
from the library are passed to the PasswordScoringBuilder
(which acts as a
facade for StreamBuilder
), and that's where the widget tree is constructed.
Usage #
-
Declare default handler for scorer isolate somewhere in your code - it has to be global function or static member of some class!
import 'dart:isolate'; import 'package:dart_zxcvbn/dart_zxcvbn.dart'; import 'package:dart_zxcvbn_language_common/dart_zxcvbn_language_common.dart'; import 'package:dart_zxcvbn_language_en/dart_zxcvbn_language_en.dart'; Future<void> handleScoring(SendPort sendPort) async { ReceivePort receivePort = ReceivePort(); sendPort.send(receivePort.sendPort); final langCommon = LanguageCommon(); final langEn = LanguageEn(); zxcvbn.setOptions(Options( dictionary: Dictionary.merge([ langCommon.dictionary, langEn.dictionary, ]), graphs: langCommon.adjacencyGraphs, translations: langCommon.translations, )); // Used to refresh response when locale changes String lastPassword = ''; await for (var message in receivePort) { if (message is Locale) { zxcvbn.setOptions(Options( translations: message.languageCode == 'en' ? langEn.translations : langCommon.translations, )); } lastPassword = message is String ? message : lastPassword; if (lastPassword.isNotEmpty) { final result = zxcvbn(lastPassword); sendPort.send(result); } } }
-
Use
PasswordScoringBuilder
to build your UIPasswordScoringBuilder( handler: handleScoring, loadingPlaceholder: const Center( child: CircularProgressIndicator(), ), builder: ( BuildContext context, Result? data, PasswordScoringHelper helper, ) { return Placeholder(); }, );
Related packages #
Package | Details |
---|---|
dart_zxcvbn | README | pub |
dart_zxcvbn_language_common | README | pub |
dart_zxcvbn_language_en | README | pub |
dart_zxcvbn_language_pl | README | pub |
flutter_password_scoring | README | pub |
License #
- see LICENSE