
from django import forms
from django.contrib.auth.password_validation import validate_password
from . import models


class UserCreationForm(forms.ModelForm):
    class Meta:
        model = models.User
        fields = ['email']

    password1 = forms.CharField(
        label="Password",
        strip=False,
        widget=forms.PasswordInput,
    )
    password2 = forms.CharField(
        label="Password confirmation",
        widget=forms.PasswordInput,
        strip=False,
        help_text="Enter the same password as before, for verification.",
    )

    def clean_password1(self):
        password1 = self.cleaned_data['password1']
        validate_password(password1)
        return password1

    def clean_password2(self):
        password1 = self.cleaned_data['password1']
        password2 = self.cleaned_data['password2']
        if password1 != password2:
            raise forms.ValidationError("The two password fields didn't match.")
        return password2

    def save(self, commit=True):
        user = super(UserCreationForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password1"])
        if commit:
            user.save()
        return user

@@ -617,33 +617,37 @@
 elf.cleaned_data
-%5B
+.get(
 'password1'%5D%0A   
@@ -633,33 +633,33 @@
 .get('password1'
-%5D
+)
 %0A        validat
@@ -766,33 +766,37 @@
 elf.cleaned_data
-%5B
+.get(
 'password1'%5D%0A   
@@ -790,17 +790,17 @@
 ssword1'
-%5D
+)
 %0A       
@@ -829,17 +829,21 @@
 ned_data
-%5B
+.get(
 'passwor
@@ -845,17 +845,17 @@
 ssword2'
-%5D
+)
 %0A       
@@ -868,16 +868,44 @@
 ssword1 
+and password2 and password1 
 != passw

fix keyerror