Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

448
Views
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'
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

if password and ...:

This checks if it has a value and if the value has the other conditions met

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!