[core] Fix Password Validations (#133)

This commit fixes the password validations. In #130 we introduced some
stronger password policies to forbid weak passwords, but forgot to
change it in all places. Now the same rules are also applying when a
user changes his password or resets his password.

During the sign in we do not use the same rules, to not block users
which have already signed up, with a password which doesn't match the
rules.
This commit is contained in:
Rico Berger
2024-02-10 15:31:56 +01:00
committed by GitHub
parent ca5866ac13
commit babce57c80
4 changed files with 29 additions and 14 deletions

View File

@@ -27,14 +27,22 @@ class _ResetPasswordState extends State<ResetPassword> {
/// [_validatePassword] validates the email address provided via the
/// [TextField] of the [_passwordController]. The password field can not be
/// empty and must have a minimum length of 6 characters.
/// empty and must have a minimum length of 8 characters. The password must
/// also contain at least one upper case letter, one lower case letter and one
/// number.
String? _validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
if (value.length < 6) {
return 'Password must be a least 6 characters long';
if (value.length < 8) {
return 'Password must be a least 8 characters long';
}
String pattern = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,}$';
RegExp regExp = RegExp(pattern);
if (!regExp.hasMatch(value)) {
return 'Password must contain at least one upper case letter, one lower case letter and one number';
}
return null;

View File

@@ -24,14 +24,22 @@ class _SettingsProfilePasswordState extends State<SettingsProfilePassword> {
/// [_validatePassword] validates the email address provided via the
/// [TextField] of the [_newPasswordController]. The password field can not be
/// empty and must have a minimum length of 6 characters.
/// empty and must have a minimum length of 8 characters. The password must
/// also contain at least one upper case letter, one lower case letter and one
/// number.
String? _validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
if (value.length < 6) {
return 'Password must be a least 6 characters long';
if (value.length < 8) {
return 'Password must be a least 8 characters long';
}
String pattern = r'^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9]).{8,}$';
RegExp regExp = RegExp(pattern);
if (!regExp.hasMatch(value)) {
return 'Password must contain at least one upper case letter, one lower case letter and one number';
}
return null;

View File

@@ -47,18 +47,15 @@ class _SignInWithFeedDeckState extends State<SignInWithFeedDeck> {
return null;
}
/// [_validatePassword] validates the email address provided via the
/// [TextField] of the [_passwordController]. The password field can not be
/// empty and must have a minimum length of 6 characters.
/// [_validatePassword] validates the password provided via the [TextField] of
/// the [_passwordController]. In opposite to the sign up, reset password and
/// change password validations, we just check that the password field is not
/// empty.
String? _validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';
}
if (value.length < 6) {
return 'Password must be a least 6 characters long';
}
return null;
}

View File

@@ -56,7 +56,9 @@ class _SignUpState extends State<SignUp> {
/// [_validatePassword] validates the email address provided via the
/// [TextField] of the [_passwordController]. The password field can not be
/// empty and must have a minimum length of 6 characters.
/// empty and must have a minimum length of 8 characters. The password must
/// also contain at least one upper case letter, one lower case letter and one
/// number.
String? _validatePassword(String? value) {
if (value == null || value.isEmpty) {
return 'Password is required';