AttributeError: 'NoneType' object has no attribute 'lower'; password validation

When registering a User, the desired user password is checked against a list of disallowed passwords. Yet when the password is passed to a validator method, the following error is raised:

AttributeError: 'NoneType' object has no attribute 'lower'

Why is the validate() method being invoked as is if password is None when in fact it is truthy?


from django.contrib.auth.models import User
from django.contrib.auth.password_validation import (
    validate_password, CommonPasswordValidator, NumericPasswordValidator
)

from rest_framework import serializers


class LoginSerializer(UsernameSerializer):

    password = serializers.RegexField(
        r"[0-9A-Za-z]+", min_length=5, max_length=8
    )

    def validate(self, data):
        username = data['username']
        password = data['password']
        try:
            validate_password(password, password_validators=[
                CommonPasswordValidator, NumericPasswordValidator
            ])
        except serializers.ValidationError:
            if username == password:
                pass
            raise serializers.ValidationError("Invalid password")
        else:
            return data

    class Meta:
        fields = ['username', 'password']
        model = User
-> for validator in password_validators:
(Pdb) n
> \auth\password_validation.py(46)validate_password()
-> try:
(Pdb) n
> \auth\password_validation.py(47)validate_password()
-> validator.validate(password, user)
(Pdb) password
'Bingo'
(Pdb) user
(Pdb) password
'Bingo'
(Pdb) s
--Call--
> \auth\password_validation.py(180)validate()
-> def validate(self, password, user=None):
(Pdb) password
(Pdb) n
> \django\contrib\auth\password_validation.py(181)validate()
-> if password.lower().strip() in self.passwords:
(Pdb) n
AttributeError: 'NoneType' object has no attribute 'lower'


from Recent Questions - Stack Overflow https://ift.tt/3cWVNJn
https://ift.tt/eA8V8J

Comments

Popular posts from this blog

Today Walkin 14th-Sept

Hibernate Search - Elasticsearch with JSON manipulation

Spring Elasticsearch Operations