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

password format verification #373

Merged
merged 3 commits into from
Jun 4, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/login/tools/constants.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ class LoginTextConstants {
static const String password = 'Mot de passe';
static const String passwordLengthError =
'Le mot de passe doit faire au moins 6 caractères';
static const String passwordUppercaseError =
'Le mot de passe doit contenir au moins une majuscule';
static const String passwordLowercaseError =
'Le mot de passe doit contenir au moins une minucule';
static const String passwordNumberError =
'Le mot de passe doit contenir au moins un chiffre';
static const String passwordSpecialCaracterError =
'Le mot de passe doit contenir au moins un caractère spécial';
static const String passwordMustMatch =
'Les mots de passe doivent correspondre';
static const String passwordStrengthVeryWeak = 'Très faible';
Expand Down
14 changes: 13 additions & 1 deletion lib/login/ui/components/login_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ class CreateAccountField extends HookConsumerWidget {
final bool isPassword;
final bool mustBeInt;
final String? Function(String?)? validator;
const CreateAccountField({
final dict = {
RegExp(r'[A-Z]'): LoginTextConstants.passwordUppercaseError,
RegExp(r'[a-z]'): LoginTextConstants.passwordLowercaseError,
RegExp(r'[0-9]'): LoginTextConstants.passwordNumberError,
RegExp(r'[!@#$%^&*(),.?":{}|<>]'):
Foukki marked this conversation as resolved.
Show resolved Hide resolved
LoginTextConstants.passwordSpecialCaracterError,
};
CreateAccountField({
super.key,
required this.controller,
required this.label,
Expand Down Expand Up @@ -117,6 +124,11 @@ class CreateAccountField extends HookConsumerWidget {
} else if (isPassword && value.length < 6) {
return LoginTextConstants.passwordLengthError;
}
for (var key in dict.keys) {
if (isPassword && !value.contains(key)) {
return dict[key];
}
}
if (mustBeInt && int.tryParse(value) == null) {
return LoginTextConstants.mustBeIntError;
}
Expand Down