Python 设置使用SHA 256加密的Jupyter实验室密码

Python 设置使用SHA 256加密的Jupyter实验室密码,python,ubuntu,jupyter-notebook,jupyter-lab,sha,Python,Ubuntu,Jupyter Notebook,Jupyter Lab,Sha,我目前正在Ubuntu 18.04服务器上运行Jupyter实验室服务。我已使用以下命令在我的实验室上设置密码: $ jupyter notebook --generate-config $ jupyter notebook password 它以以下输出响应: [NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json 之后,我在.jupyter/jupyte

我目前正在Ubuntu 18.04服务器上运行Jupyter实验室服务。我已使用以下命令在我的实验室上设置密码:

$ jupyter notebook --generate-config
$ jupyter notebook password
它以以下输出响应:

[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json
之后,我在.jupyter/jupyter\u notebook\u config.py文件中添加配置设置,如下所示:

c.NotebookApp.password = u'sha1:bcd259ccf...<my hashed password here>'
c.NotebookApp.password=u'sha1:bcd259ccf…'
我想要的是获得SHA256哈希密码,而不是SHA1,这纯粹是因为SHA256哈希提供了额外的加密级别,因为它的长度更大


我想知道是否有办法使这成为可能?目前,我已经尝试了几个选项,但似乎都不起作用。

笔记本电脑.auth模块提供了一个名为
passwd
的功能。第二个参数是算法。您可以使用该函数获取SHA256哈希密码

"""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 :func:`hashlib.new`, or 'argon2').

Returns
-------
hashed_passphrase : str
    Hashed password, in the format 'hash_algorithm:salt:passphrase_hash'."""

from notebook.auth import passwd

my_password = "spam-and-eggs"

hashed_password = passwd(passphrase=my_password, algorithm='sha256')

print(hashed_password)

输出:
sha256:128c5116bc40:94CFE1EEF8703B657A7EF28AF741FA05465C7A735645A65040BD51BCCC6039B
笔记本。身份验证模块提供一个名为
passwd
的函数。第二个参数是算法。您可以使用该函数获取SHA256哈希密码

"""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 :func:`hashlib.new`, or 'argon2').

Returns
-------
hashed_passphrase : str
    Hashed password, in the format 'hash_algorithm:salt:passphrase_hash'."""

from notebook.auth import passwd

my_password = "spam-and-eggs"

hashed_password = passwd(passphrase=my_password, algorithm='sha256')

print(hashed_password)
输出:
sha256:128c5116bc40:94CFE1EEF8703B657A7EF28AF741FA05465C7A735645A65040BD51BCCC6039B