【问题标题】:Set Jupyter Lab password encrypted with SHA 256设置使用 SHA 256 加密的 Jupyter Lab 密码
【发布时间】:2021-05-09 19:40:06
【问题描述】:

我目前正在我的 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_notebook_config.py 文件中添加配置设置,如下所示:

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

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

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

【问题讨论】:

    标签: python ubuntu jupyter-notebook jupyter-lab sha


    【解决方案1】:

    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

    【讨论】:

      猜你喜欢
      • 2017-03-02
      • 1970-01-01
      • 1970-01-01
      • 2014-07-16
      • 1970-01-01
      • 1970-01-01
      • 2022-07-14
      • 2022-11-10
      • 2011-05-18
      相关资源
      最近更新 更多