Managers

The PasswordHistory model has a custom manager that has the following helper functions:

PasswordHistoryManager

class password_policies.managers.PasswordHistoryManager
delete_expired(user, offset=None)

Deletes expired password history entries from the database(s).

Parameters:
  • user – A User instance.
  • offset (int) – A number specifying how much entries are to be kept in the user’s password history. Defaults to PASSWORD_HISTORY_COUNT.
change_required(user)

Checks if the user needs to change his/her password.

Parameters:user (object) – A User instance.
Returns:True if the user needs to change his/her password, False otherwise.
Return type:bool
check_password(user, raw_password)

Compares a raw (UNENCRYPTED!!!) password to entries in the users’s password history.

Parameters:
  • user (object) – A User instance.
  • raw_password (str) – A unicode string representing a password.
Returns:

False if a password has been used before, True if not.

Return type:

bool

get_newest(user)

Gets the newest password history entry.

Parameters:user (object) – A User instance.
Returns:A PasswordHistory instance if found, None if not.