Warning

This documentation covers a development version of IPython. The development version may differ significantly from the latest stable release.

Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: lib.security

Password generation for the IPython notebook.

2 Functions

IPython.lib.security.passwd(passphrase=None, algorithm='sha1')

Generate hashed password and salt for use in notebook configuration.

In the notebook configuration, set c.NotebookApp.password to the generated string.

Parameters
  • passphrase (str) – Password to hash. If unspecified, the user is asked to input and verify a password.

  • algorithm (str) – Hashing algorithm to use (e.g, ‘sha1’ or any argument supported by hashlib.new()).

Returns

hashed_passphrase – Hashed password, in the format ‘hash_algorithm:salt:passphrase_hash’.

Return type

str

Examples

>>> passwd('mypassword')
'sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12'
IPython.lib.security.passwd_check(hashed_passphrase, passphrase)

Verify that a given passphrase matches its hashed version.

Parameters
  • hashed_passphrase (str) – Hashed password, in the format returned by passwd.

  • passphrase (str) – Passphrase to validate.

Returns

valid – True if the passphrase matches the hash.

Return type

bool

Examples

>>> from IPython.lib.security import passwd_check
>>> passwd_check('sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a',
...              'mypassword')
True
>>> passwd_check('sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a',
...              'anotherpassword')
False