Show password strength

This commit is contained in:
Vishnu Mohandas 2021-01-05 20:10:43 +05:30
parent d3d9e2bbf7
commit e423456935
3 changed files with 112 additions and 97 deletions

View file

@ -28,111 +28,118 @@ class _PasswordEntryPageState extends State<PasswordEntryPage> {
} }
Widget _getBody() { Widget _getBody() {
return SingleChildScrollView( return Column(
child: Container( children: [
padding: EdgeInsets.fromLTRB(16, 40, 16, 16), FlutterPasswordStrength(
child: Column( password: _passwordController1.text,
children: [ backgroundColor: Colors.grey[850],
// Image.asset( strengthCallback: (strength) {
// "assets/vault.png", debugPrint(strength.toString());
// width: 196, },
// height: 196,
// ),
Padding(padding: EdgeInsets.all(12)),
Text(
"enter a password we can use to encrypt your data",
textAlign: TextAlign.center,
style: TextStyle(
height: 1.3,
),
),
Padding(padding: EdgeInsets.all(8)),
Text("we don't store this password, so if you forget, "),
Text.rich(
TextSpan(
text: "we cannot decrypt your data",
style: TextStyle(
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold,
)),
style: TextStyle(
height: 1.3,
),
textAlign: TextAlign.center,
),
Padding(padding: EdgeInsets.all(12)),
Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
child: TextFormField(
decoration: InputDecoration(
hintText: "password",
contentPadding: EdgeInsets.all(20),
),
controller: _passwordController1,
autofocus: false,
autocorrect: false,
keyboardType: TextInputType.visiblePassword,
onChanged: (_) {
setState(() {});
},
),
),
Padding(padding: EdgeInsets.all(8)),
Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
child: TextFormField(
decoration: InputDecoration(
hintText: "password again",
contentPadding: EdgeInsets.all(20),
),
controller: _passwordController2,
autofocus: false,
autocorrect: false,
obscureText: true,
keyboardType: TextInputType.visiblePassword,
onChanged: (_) {
setState(() {});
},
),
),
Padding(padding: EdgeInsets.all(16)),
FlutterPasswordStrength(
password: _passwordController1.text,
strengthCallback: (strength) {
debugPrint(strength.toString());
}),
Padding(padding: EdgeInsets.all(16)),
Container(
width: double.infinity,
height: 44,
padding: EdgeInsets.fromLTRB(32, 0, 32, 0),
child: button(
"set password",
onPressed: _passwordController1.text.isNotEmpty &&
_passwordController2.text.isNotEmpty
? () {
if (_passwordController1.text !=
_passwordController2.text) {
showErrorDialog(context, "Uhm...",
"The passphrases you entered don't match.");
} else {
_showPassphraseConfirmationDialog();
}
}
: null,
)),
],
), ),
), Expanded(
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.fromLTRB(16, 36, 16, 16),
child: Column(
children: [
// Image.asset(
// "assets/vault.png",
// width: 196,
// height: 196,
// ),
Padding(padding: EdgeInsets.all(12)),
Text(
"enter a password we can use to encrypt your data",
textAlign: TextAlign.center,
style: TextStyle(
height: 1.3,
),
),
Padding(padding: EdgeInsets.all(8)),
Text("we don't store this password, so if you forget, "),
Text.rich(
TextSpan(
text: "we cannot decrypt your data",
style: TextStyle(
decoration: TextDecoration.underline,
fontWeight: FontWeight.bold,
)),
style: TextStyle(
height: 1.3,
),
textAlign: TextAlign.center,
),
Padding(padding: EdgeInsets.all(12)),
Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
child: TextFormField(
decoration: InputDecoration(
hintText: "password",
contentPadding: EdgeInsets.all(20),
),
controller: _passwordController1,
autofocus: false,
autocorrect: false,
keyboardType: TextInputType.visiblePassword,
onChanged: (_) {
setState(() {});
},
),
),
Padding(padding: EdgeInsets.all(8)),
Padding(
padding: const EdgeInsets.fromLTRB(32, 0, 32, 0),
child: TextFormField(
decoration: InputDecoration(
hintText: "password again",
contentPadding: EdgeInsets.all(20),
),
controller: _passwordController2,
autofocus: false,
autocorrect: false,
obscureText: true,
keyboardType: TextInputType.visiblePassword,
onChanged: (_) {
setState(() {});
},
),
),
Padding(padding: EdgeInsets.all(16)),
Container(
width: double.infinity,
height: 44,
padding: EdgeInsets.fromLTRB(32, 0, 32, 0),
child: button(
"set password",
onPressed: _passwordController1.text.isNotEmpty &&
_passwordController2.text.isNotEmpty
? () {
if (_passwordController1.text !=
_passwordController2.text) {
showErrorDialog(context, "Uhm...",
"The passwords you entered don't match.");
} else {
_showPasswordConfirmationDialog();
}
}
: null,
)),
],
),
),
),
),
],
); );
} }
void _showPassphraseConfirmationDialog() { void _showPasswordConfirmationDialog() {
AlertDialog alert = AlertDialog( AlertDialog alert = AlertDialog(
title: Text("Confirmation"), title: Text("Confirmation"),
content: SingleChildScrollView( content: SingleChildScrollView(
child: Column(children: [ child: Column(children: [
Text("The passphrase you are promising to never forget is"), Text("The password you are promising to never forget is"),
Padding(padding: EdgeInsets.all(8)), Padding(padding: EdgeInsets.all(8)),
Text(_passwordController1.text, Text(_passwordController1.text,
style: TextStyle( style: TextStyle(

View file

@ -267,6 +267,13 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "0.8.0" version: "0.8.0"
flutter_password_strength:
dependency: "direct main"
description:
name: flutter_password_strength
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
flutter_secure_storage: flutter_secure_storage:
dependency: "direct main" dependency: "direct main"
description: description:

View file

@ -71,6 +71,7 @@ dependencies:
fluttercontactpicker: ^3.1.0 fluttercontactpicker: ^3.1.0
in_app_purchase: ^0.3.4+16 in_app_purchase: ^0.3.4+16
expansion_card: ^0.1.0 expansion_card: ^0.1.0
flutter_password_strength: ^0.1.4
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: