使用SHA 256加密设置Jupyter Lab密码

6

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

$ jupyter notebook --generate-config
$ jupyter notebook password

它会回应以下输出:
[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json

然后我将以下配置设置添加到.jupyter/jupyter_notebook_config.py文件中:

c.NotebookApp.password = u'sha1:bcd259ccf...<my hashed password here>'

我想要的是得到SHA 256哈希密码,而不是SHA 1,纯粹是因为SHA 256哈希由于其更大的长度提供了额外的加密级别。

我在想是否有方法使这成为可能?目前我尝试了几个选项,但似乎没有一个可行。


请查看此链接获取更新版本:点击这里 - undefined
2个回答

12

notebook.auth 模块提供了一个名为 passwd 的函数。第二个参数是算法。你可以使用该函数获取 SHA 256 哈希密码。

"""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:94cfe1eef8703b657a7ef28af741fa05465c7a7355645a65040bd51bccc6039b


1
是否也可以在不使用Jupyter Python库的情况下创建密码? - Sebi B

0
轻松使用.conf文件指南:
from notebook.auth import passwd
passwd("somepassword")

将文本从英文翻译成中文。仅返回翻译后的文本内容:

输出:'argon2:$argon2id$v=19$m=102.....'

然后将整个字符串放入您的.conf文件中


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接