As the question mentioned above, I will try to use a specific additional rule to verify the password during the registration process. An additional rule should be that the password is checked if it contains at least one number, one letter and one special character.
My approach to solving this problem. I created a file called validators.py.
from django.core.exceptions import ValidationError
class CustomPasswortValidator:
def validate(value):
if not any(char.isdigit() for char in value):
raise ValidationError(_('Password must contain at least 1 digit.'))
if not any(char.isalpha() for char in value):
raise ValidationError(_('Password must contain at least 1 letter.'))
special_characters = "[~\!@#\$%\^&\*\(\)_\+{}\":;'\[\]]"
if not any(char in special_characters for char in value):
raise ValidationError(_('Password must contain at least 1 letter.'))
My user registration form is as follows:
from django import forms
from django.contrib.auth.forms import UserCreationForm
from django.contrib.auth.models import User
class RegistrationForm(UserCreationForm):
first_name = forms.CharField(max_length=30, required=False,
help_text='Optional.')
last_name = forms.CharField(max_length=30, required=False,
help_text='Optional.')
email = forms.EmailField(max_length=254, help_text='Required. Inform a valid email address.')
class Meta:
model = User
fields = ('username', 'first_name', 'last_name', 'email', 'password1', 'password2', )
I do not understand how I tell django that my own password validator should be used next to django AUTH_PASSWORD_VALIDATORS.
Texas