diff --git a/flask_security/core.py b/flask_security/core.py index be736a0..43dd671 100644 --- a/flask_security/core.py +++ b/flask_security/core.py @@ -110,6 +110,7 @@ _default_messages = { 'EMAIL_NOT_PROVIDED': ('Email not provided', 'error'), 'INVALID_EMAIL_ADDRESS': ('Invalid email address', 'error'), 'PASSWORD_NOT_PROVIDED': ('Password not provided', 'error'), + 'PASSWORD_INVALID_LENGTH': ('Password must be at least 6 characters', 'error'), 'USER_DOES_NOT_EXIST': ('Specified user does not exist', 'error'), 'INVALID_PASSWORD': ('Invalid password', 'error'), 'PASSWORDLESS_LOGIN_SUCCESSFUL': ('You have successfuly logged in.', 'success'), diff --git a/flask_security/forms.py b/flask_security/forms.py index a25869c..e16c65d 100644 --- a/flask_security/forms.py +++ b/flask_security/forms.py @@ -69,6 +69,7 @@ class Length(ValidatorMixin, wtf.Length): email_required = Required(message='EMAIL_NOT_PROVIDED') email_validator = Email(message='INVALID_EMAIL_ADDRESS') password_required = Required(message='PASSWORD_NOT_PROVIDED') +password_length = Length(min=6, max=128, message='PASSWORD_INVALID_LENGTH') def get_form_field_label(key): @@ -122,8 +123,7 @@ class PasswordFormMixin(): class NewPasswordFormMixin(): password = PasswordField(get_form_field_label('password'), - validators=[password_required, - Length(min=6, max=128)]) + validators=[password_required, password_length]) class PasswordConfirmFormMixin(): @@ -256,8 +256,7 @@ class ChangePasswordForm(Form, PasswordFormMixin): """The default change password form""" new_password = PasswordField(get_form_field_label('new_password'), - validators=[password_required, - Length(min=6, max=128)]) + validators=[password_required, password_length]) new_password_confirm = PasswordField(get_form_field_label('retype_password'), validators=[EqualTo('new_password', message='RETYPE_PASSWORD_MISMATCH')]) diff --git a/tests/configured_tests.py b/tests/configured_tests.py index b8ae248..0d51fe3 100644 --- a/tests/configured_tests.py +++ b/tests/configured_tests.py @@ -459,7 +459,7 @@ class ChangePasswordTest(SecurityTest): 'new_password_confirm': 'a' }, follow_redirects=True) self.assertNotIn('You successfully changed your password', r.data) - self.assertIn('Field must be between', r.data) + self.assertIn('Password must be at least 6 characters', r.data) def test_change_password_success(self): self.authenticate()