From 1cae8cbb0f85867d65853be1a239a927369f9810 Mon Sep 17 00:00:00 2001 From: peppelinux Date: Thu, 19 Oct 2023 14:54:58 +0200 Subject: [PATCH] feat: Password field --- django_form_builder/dynamic_fields.py | 35 +++++++++++++++++++++++---- setup.py | 2 +- 2 files changed, 31 insertions(+), 6 deletions(-) diff --git a/django_form_builder/dynamic_fields.py b/django_form_builder/dynamic_fields.py index c621220..f422299 100644 --- a/django_form_builder/dynamic_fields.py +++ b/django_form_builder/dynamic_fields.py @@ -585,11 +585,19 @@ class CaptchaField(BaseCustomField): widget = CaptchaWidget def define_value(self, custom_value, **kwargs): - self.widget = CaptchaWidget(attrs={'value': custom_value, - 'hidden_field': kwargs.get('hidden_field', ''), - 'lang': kwargs.get('lang', getattr(settings, - 'CAPTCHA_DEFAULT_LANG', - CAPTCHA_DEFAULT_LANG))}) + self.widget = CaptchaWidget( + attrs={ + 'value': custom_value, + 'hidden_field': kwargs.get('hidden_field', ''), + 'lang': kwargs.get( + 'lang', getattr( + settings, + 'CAPTCHA_DEFAULT_LANG', + CAPTCHA_DEFAULT_LANG + ) + ) + } + ) class CustomCaptchaComplexField(BaseCustomField): @@ -718,3 +726,20 @@ def define_value(self, custom_value, **kwargs): if custom_value: elements = _split_choices_in_list_canc(custom_value) self.choices = elements + + +class CustomPasswordField(CharField, BaseCustomField): + """ + PasswordField + """ + field_type = _("Password") + widget = forms.PasswordInput + PASSWORD_SEC_REGEX = getattr( + settings, + 'PASSWORD_SEC_REGEX', + "^(?=.*?[A-Z])(?=.*?[a-z])(?=.*?[0-9])(?=.*?[#?!@$%^&*-]).{8,}$" + ) + + def raise_error(self, name, cleaned_data, **kwargs): + if not re.match(self.PASSWORD_SEC_REGEX, cleaned_data): + return ["Password is not secure enough, please add more entropy"] diff --git a/setup.py b/setup.py index 5abc9af..6614b58 100644 --- a/setup.py +++ b/setup.py @@ -14,7 +14,7 @@ setup( name='django-form-builder', - version='0.17.1', + version='0.2.0', packages=find_packages(), package_data={'': ['*.wav']}, data_files=[