From 893c2d6f420774728e112860aeabe3c2e3857abc Mon Sep 17 00:00:00 2001 From: Frank Sauerburger <frank@sauerburger.com> Date: Wed, 3 Mar 2021 23:59:39 +0100 Subject: [PATCH] Enforce password repetition --- app/owlca/forms.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/app/owlca/forms.py b/app/owlca/forms.py index 2ca7bfc..2546165 100644 --- a/app/owlca/forms.py +++ b/app/owlca/forms.py @@ -15,6 +15,11 @@ class CaCreateForm(forms.Form): widget=forms.PasswordInput(), required=True, ) + repeat = forms.CharField( + max_length=128, + widget=forms.PasswordInput(), + required=True, + ) length = forms.TypedChoiceField( choices=length_choices, coerce=int, @@ -43,6 +48,18 @@ class CaCreateForm(forms.Form): public = forms.BooleanField(required=False) + def clean(self): + """Custom validation to match passwords""" + cleaned_data = super().clean() + + password = cleaned_data.get('password') + repeat = cleaned_data.get('repeat') + + if password and repeat: + if password != repeat: + raise forms.ValidationError("The two password fields must match") + + return cleaned_data class CsrCreateForm(forms.Form): csr_pem = forms.FileField() -- GitLab