Checking input password for user

Its work well, but i have problem with checking password, how control validation of input password with default saving?

class MyAuthenticationForm(AuthenticationForm):
# checking for username  in DB:
def clean_username(self):
    username = self.cleaned_data['username']
    try:
        User.objects.get(username=username)
    except User.DoesNotExist:
        raise forms.ValidationError(f"The {username} is incorrect username.")
    return username

There is a function called check_password() in User model.

So you can check password via:

user = User.objects.get(username=username)
user.check_password(password)
Back to Top