Skip to main content

CommonPasswordValidator

Validate that the password is not a common password.

Attributes

AttributeTypeDescription
passwordssetA set of lowercased, stripped strings representing common passwords loaded from the specified file path for membership testing during validation.

Constructor

Signature

def CommonPasswordValidator(
password_list_path: str|Path = DEFAULT_PASSWORD_LIST_PATH
) - > null

Parameters

NameTypeDescription
password_list_path`strPath` = DEFAULT_PASSWORD_LIST_PATH

Signature

def CommonPasswordValidator(
password_list_path: str | Path = DEFAULT_PASSWORD_LIST_PATH
)

Parameters

NameTypeDescription
password_list_path`strPath` = DEFAULT_PASSWORD_LIST_PATH

Methods


DEFAULT_PASSWORD_LIST_PATH()

@classmethod
def DEFAULT_PASSWORD_LIST_PATH() - > Path

Returns the absolute file path to the default gzipped text file containing the list of common passwords.

Returns

TypeDescription
PathThe resolved Path object pointing to 'common-passwords.txt.gz' within the validator's directory

validate()

@classmethod
def validate(
password: string,
user: object = None
) - > None

Checks if the provided password exists in the forbidden password list and raises a ValidationError if a match is found.

Parameters

NameTypeDescription
passwordstringThe raw password string to be checked against the common password list
userobject = NoneThe user instance associated with the password, though not used in this specific validation logic

Returns

TypeDescription
NoneNothing is returned if the password passes validation

get_error_message()

@classmethod
def get_error_message() - > string

Provides the localized error message displayed to the user when a password is rejected for being too common.

Returns

TypeDescription
stringA translated string stating that the password is too common

get_help_text()

@classmethod
def get_help_text() - > string

Provides the localized instructional text used to inform users about password complexity requirements.

Returns

TypeDescription
stringA translated string explaining that commonly used passwords are not permitted