Set Jupyter Lab password encrypted with SHA 256
Asked Answered
G

2

6

I am currently running a Jupyter lab service on my Ubuntu 18.04 server. I have set the password on my lab using the following command:

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

It responds with the following output:

[NotebookPasswordApp] Wrote hashed password to /Users/you/.jupyter/jupyter_notebook_config.json

After that I add the config settings in .jupyter/jupyter_notebook_config.py file as follows:

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

What I want is to get SHA 256 hashed password instead of SHA 1 purely because of the additional level of encryption offered by SHA 256 hash due to its bigger length.

I am wondering if there's a way to make this possible? Currently I have tried several options and none of them seem to work.

Gitagitel answered 5/2, 2021 at 12:55 Comment(1)
For newer versions see thisTwoply
L
13

The notebook.auth module offers a function called passwd. The second argument is an algorithm. You can use that function to obtain a SHA 256 hashed password.

"""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)

OUTPUT: sha256:128c5116bc40:94cfe1eef8703b657a7ef28af741fa05465c7a7355645a65040bd51bccc6039b

Lambaste answered 5/2, 2021 at 14:52 Comment(1)
Is it also possible to create a password without the jupyter python lib?Anthracoid
D
1

Easily use the .conf file guidance:

from notebook.auth import passwd
passwd("somepassword")

Output: 'argon2:$argon2id$v=19$m=102.....'

Then put the entire string in your .conf file

Dumfound answered 24/10, 2023 at 12:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.