Dashboard Authentication - Login Audit

The audit log of failed sign-ins, which the console’s account api writes. See Web Console Api.

The audit log of failed sign-ins to the web console.

Each failed sign-in is logged once, at WARNING, so that it is emitted whether or not the account app’s logging switch is on. The line names why the sign-in failed, as a LoginFailure, and who tried, as login_identity(): a keyed hash of the email address, not the address itself. People sometimes type their password into the email field, and the platform’s logs are kept and searched, so the text that someone typed is never logged.

Whoever helps a user with a sign-in problem computes the same hash from the user’s verified email address, and searches the logs for it:

from smarter.apps.account.login_audit import login_identity

login_identity("user@example.com")  # e.g. 'a3f09c41d27e5b18'

The hash is keyed with the platform’s SECRET_KEY, so it cannot be reversed with a list of known email addresses without that key, and differs between platforms.

smarter.apps.account.login_audit.LOGIN_IDENTITY_LENGTH = 16

The number of hexadecimal characters of login_identity().

smarter.apps.account.login_audit.LOGIN_IDENTITY_SALT = 'smarter.apps.account.login_audit.login_identity'

The salt of login_identity()’s hash.

Changing it changes every identity.

class smarter.apps.account.login_audit.LoginFailure(*values)[source]

Bases: StrEnum

Why a sign-in failed.

ERROR = 'error'

The sign-in raised an exception.

INACTIVE_ACCOUNT = 'inactive_account'

The user exists but is not active.

INVALID_FORM = 'invalid_form'

The form was incomplete, or its email address was not valid.

NO_PASSWORD = 'no_password'

The user has no password, e.g. because they signed up with Google or GitHub.

UNKNOWN_ACCOUNT = 'unknown_account'

No user has the email address.

WRONG_PASSWORD = 'wrong_password'

The user is active and has a password, and the password did not match.

smarter.apps.account.login_audit.log_login_failure(email, failure)[source]

Log a failed sign-in.

Parameters:
Return type:

None

smarter.apps.account.login_audit.login_identity(email)[source]

Return the identity of an email address in the audit log: a keyed hash of it.

The address is stripped and lower cased first, so that the same address typed differently has the same identity.

Parameters:

email (str | None) – The email address, as typed or as stored.

Return type:

str

Returns:

LOGIN_IDENTITY_LENGTH hexadecimal characters, or "none" if there is no address.

smarter.apps.account.login_audit.password_failure(user)[source]

Return why an existing user’s password was not accepted.

Django’s ModelBackend rejects an inactive user, and a user without a usable password, as it rejects a wrong password, so the user’s own state tells them apart.

Parameters:

user (User) – The user whose sign-in failed.

Return type:

LoginFailure

Returns:

The reason.