Skip to content

passlib.hash.plaintext - Plaintext

This class stores passwords in plaintext. This is, of course, ridiculously insecure; it is provided for backwards compatibility when migrating existing applications. It should not be used for any other purpose. This class should always be the last algorithm checked, as it will recognize all hashes. It can be used directly as follows:

from passlib.hash import plaintext as plaintext

# "encrypt" password
print(plaintext.hash("password"))
# > 'password'

# verify password
print(plaintext.verify("password", "password"))
# > True
print(plaintext.verify("secret", "password"))
# > False

Tip

  • password hash usage -- for more usage examples

  • ldap_plaintext -- on LDAP systems, this format is probably more appropriate for storing plaintext passwords.

Interface

plaintext

This class stores passwords in plaintext, and follows the :ref:password-hash-api.

The :meth:~passlib.ifc.PasswordHash.hash, :meth:~passlib.ifc.PasswordHash.genhash, and :meth:~passlib.ifc.PasswordHash.verify methods all require the following additional contextual keyword:

Parameters:

  • encoding (str) –

    This controls the character encoding to use (defaults to utf-8).

    This encoding will be used to encode :class:`!str` passwords
    under Python 2, and decode :class:`!bytes` hashes under Python 3.
    

    .. versionchanged:: 1.6 The encoding keyword was added.

encrypt classmethod

encrypt(*args, **kwds)

Legacy alias for :meth:hash.

.. deprecated:: 1.7 This method was renamed to :meth:!hash in version 1.7. This alias will be removed in version 2.0, and should only be used for compatibility with Passlib 1.3 - 1.6.

needs_update classmethod

needs_update(hash, secret=None)

check if hash's configuration is outside desired bounds, or contains some other internal option which requires updating the password hash.

Parameters:

  • hash –

    hash string to examine

  • secret –

    optional secret known to have verified against the provided hash. (this is used by some hashes to detect legacy algorithm mistakes).

Returns:

  • –

    whether secret needs re-hashing.

    .. versionadded:: 1.7