passlib.exc - Exceptions and warnings¶
This module contains all the custom exceptions & warnings that may be raised by Passlib.
Exceptions¶
MissingBackendError
¶
Error raised if multi-backend handler has no available backends; or if specifically requested backend is not available.
:exc:!MissingBackendError derives
from :exc:RuntimeError, since it usually indicates
lack of an external library or OS feature.
This is primarily raised by handlers which depend on
external libraries (which is currently just
:class:~passlib.hash.bcrypt).
InternalBackendError
¶
Error raised if something unrecoverable goes wrong with backend call;
such as if crypt.crypt() returning a malformed hash.
.. versionadded:: 1.7.3
PasswordValueError
¶
Error raised if a password can't be hashed / verified for various reasons.
This exception derives from the builtin :exc:!ValueError.
May be thrown directly when password violates internal invariants of hasher
(e.g. some don't support NULL characters). Hashers may also throw more specific subclasses,
such as :exc:!PasswordSizeError.
.. versionadded:: 1.7.3
PasswordSizeError
¶
PasswordSizeError(max_size, msg=None)
Error raised if a password exceeds the maximum size allowed by Passlib (by default, 4096 characters); or if password exceeds a hash-specific size limitation.
This exception derives from :exc:PasswordValueError (above).
Many password hash algorithms take proportionately larger amounts of time and/or
memory depending on the size of the password provided. This could present
a potential denial of service (DOS) situation if a maliciously large
password is provided to an application. Because of this, Passlib enforces
a maximum size limit, but one which should be much larger
than any legitimate password. :exc:PasswordSizeError derives
from :exc:!ValueError.
.. note::
Applications wishing to use a different limit should set the
PASSLIB_MAX_PASSWORD_SIZE environmental variable before
Passlib is loaded. The value can be any large positive integer.
.. attribute:: max_size
indicates the maximum allowed size.
.. versionadded:: 1.6
PasswordTruncateError
¶
PasswordTruncateError(cls, msg=None)
Error raised if password would be truncated by hash.
This derives from :exc:PasswordSizeError (above).
Hashers such as :class:~passlib.hash.bcrypt can be configured to raises
this error by setting truncate_error=True.
.. attribute:: max_size
indicates the maximum allowed size.
.. versionadded:: 1.7
PasslibSecurityError
¶
Error raised if critical security issue is detected (e.g. an attempt is made to use a vulnerable version of a bcrypt backend).
.. versionadded:: 1.6.3
UnknownHashError
¶
UnknownHashError(message=None, value=None)
Error raised by :class:~passlib.crypto.lookup_hash if hash name is not recognized.
This exception derives from :exc:!ValueError.
As of version 1.7.3, this may also be raised if hash algorithm is known, but has been disabled due to FIPS mode (message will include phrase "disabled for fips").
As of version 1.7.4, this may be raised if a :class:~passlib.context.CryptContext
is unable to identify the algorithm used by a password hash.
.. versionadded:: 1.7
.. versionchanged: 1.7.3 added 'message' argument.
.. versionchanged:: 1.7.4 altered call signature.
TOTP Exceptions¶
TokenError
¶
TokenError(msg=None, *args, **kwds)
Base error raised by v:mod:passlib.totp when
a token can't be parsed / isn't valid / etc.
Derives from :exc:!ValueError.
Usually one of the more specific subclasses below will be raised:
- :class:
MalformedTokenError-- invalid chars, too few digits - :class:
InvalidTokenError-- no match found - :class:
UsedTokenError-- match found, but token already used
.. versionadded:: 1.7
MalformedTokenError
¶
MalformedTokenError(msg=None, *args, **kwds)
Error raised by :mod:passlib.totp when a token isn't formatted correctly
(contains invalid characters, wrong number of digits, etc)
InvalidTokenError
¶
InvalidTokenError(msg=None, *args, **kwds)
Error raised by :mod:passlib.totp when a token is formatted correctly,
but doesn't match any tokens within valid range.
UsedTokenError
¶
UsedTokenError(*args, **kwds)
Error raised by :mod:passlib.totp if a token is reused.
Derives from :exc:TokenError.
.. autoattribute:: expire_time
.. versionadded:: 1.7
Warnings¶
PasslibWarning
¶
base class for Passlib's user warnings,
derives from the builtin :exc:UserWarning.
.. versionadded:: 1.6
Minor Warnings¶
PasslibConfigWarning
¶
Warning issued when non-fatal issue is found related to the configuration
of a :class:~passlib.context.CryptContext instance.
This occurs primarily in one of two cases:
- The CryptContext contains rounds limits which exceed the hard limits imposed by the underlying algorithm.
- An explicit rounds value was provided which exceeds the limits imposed by the CryptContext.
In both of these cases, the code will perform correctly & securely; but the warning is issued as a sign the configuration may need updating.
.. versionadded:: 1.6
PasslibHashWarning
¶
Warning issued when non-fatal issue is found with parameters or hash string passed to a passlib hash class.
This occurs primarily in one of two cases:
-
A rounds value or other setting was explicitly provided which exceeded the handler's limits (and has been clamped by the :ref:
relaxed<relaxed-keyword>flag). -
A malformed hash string was encountered which (while parsable) should be re-encoded.
.. versionadded:: 1.6
Critical Warnings¶
PasslibRuntimeWarning
¶
Warning issued when something unexpected happens during runtime.
The fact that it's a warning instead of an error means Passlib was able to correct for the issue, but that it's anomalous enough that the developers would love to hear under what conditions it occurred.
.. versionadded:: 1.6
PasslibSecurityWarning
¶
Special warning issued when Passlib encounters something that might affect security.
.. versionadded:: 1.6