Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Feature: Password Entropy #207

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions authpass/lib/ui/screens/create_file.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:authpass/ui/widgets/password_input_field.dart';
import 'package:authpass/ui/widgets/primary_button.dart';
import 'package:authpass/utils/dialog_utils.dart';
import 'package:authpass/utils/extension_methods.dart';
import 'package:authpass/utils/password_entropy.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
Expand All @@ -30,13 +31,15 @@ class CreateFile extends StatefulWidget {

class _CreateFileState extends State<CreateFile> with FutureTaskStateMixin {
static final _zxcvbn = Zxcvbn();
static final _calculatePasswordEntropy=PasswordEntropy();

final GlobalKey<FormState> _formKey = GlobalKey();
final TextEditingController _databaseName = TextEditingController();
final TextEditingController _password = TextEditingController();
final FocusNode _passwordFocus = FocusNode();

Result _strength;
String _passwordEntropy;

@override
void didChangeDependencies() {
Expand Down Expand Up @@ -96,9 +99,12 @@ class _CreateFileState extends State<CreateFile> with FutureTaskStateMixin {
setState(() {
if (value.isEmpty) {
_strength = null;
_passwordEntropy = null;
} else {
_strength =
_zxcvbn.evaluate(value, userInputs: userInput);
_passwordEntropy =
_calculatePasswordEntropy.passwordEntropy(value);
}
});
},
Expand All @@ -112,6 +118,8 @@ class _CreateFileState extends State<CreateFile> with FutureTaskStateMixin {
const SizedBox(height: 8),
PasswordStrengthDisplay(strength: _strength),
const SizedBox(height: 8),
_passwordEntropy!=null?Text('Entrophy: $_passwordEntropy'):Container(),
const SizedBox(height: 8),
Text(
'The master password is used to securely encrypt your password database. Make sure to remember it, it can not be restored.',
style: Theme.of(context).textTheme.caption,
Expand Down
18 changes: 18 additions & 0 deletions authpass/lib/utils/password_entropy.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import 'dart:math';

// Entropy(H) = L * log2(N)
// L = Length of password
// N = Number of special characters

class PasswordEntropy {
String passwordEntropy(String value) {
double logBase(num x, num base) => log(x) / log(base);

final n =
RegExp(r'[!"#$%&()*+,-./:;<=>?@[\]^_`{|}~]').allMatches(value).length;

final l = value.length;

return (l * logBase(n, 2)).toStringAsFixed(2);
}
}
6 changes: 3 additions & 3 deletions authpass/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -754,7 +754,7 @@ packages:
name: meta
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0-nullsafety.4"
version: "1.3.0-nullsafety.3"
mime:
dependency: "direct main"
description:
Expand Down Expand Up @@ -1178,7 +1178,7 @@ packages:
name: stack_trace
url: "https://pub.dartlang.org"
source: hosted
version: "1.10.0-nullsafety.2"
version: "1.10.0-nullsafety.1"
stream_channel:
dependency: transitive
description:
Expand Down Expand Up @@ -1485,5 +1485,5 @@ packages:
source: hosted
version: "0.0.1"
sdks:
dart: ">=2.10.0-110 <=2.11.0-213.0.dev"
dart: ">=2.10.0-110 <2.11.0"
flutter: ">=1.18.0-6.0.pre <2.0.0"