Skip to content

Commit

Permalink
feat: Password field
Browse files Browse the repository at this point in the history
  • Loading branch information
peppelinux committed Oct 19, 2023
1 parent b3166f1 commit 1cae8cb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 6 deletions.
35 changes: 30 additions & 5 deletions django_form_builder/dynamic_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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"]
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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=[
Expand Down

0 comments on commit 1cae8cb

Please sign in to comment.