using getpass() to prompt for a new password

master
manetta 2 years ago
parent 1bf11efce0
commit 273c122eea

@ -3,29 +3,33 @@ import os
from hashlib import sha1
from jinja2 import Environment, FileSystemLoader
from random import shuffle
from getpass import getpass
username = input("Username: ")
port = input("Port: ")
servername = input("Servername: ")
templates_folder = "templates"
passwords_file = "passwords.txt"
#passwords_file = "passwords.txt"
template_env = Environment(loader=FileSystemLoader(templates_folder))
nbconfig = template_env.get_template("jupyter_notebook_config.py")
passwords = open(passwords_file).read().strip().splitlines()
passwords = [w.lower() for w in passwords]
shuffle(passwords)
password = "".join(passwords[:3])
#passwords = open(passwords_file).read().strip().splitlines()
#passwords = [w.lower() for w in passwords]
#shuffle(passwords)
#password = "".join(passwords[:3])
userdata = {}
userdata['username'] = username
userdata['port'] = port
userdata['servername'] = servername
password = getpass(f"New password: ")
userdata['password'] = password
# userdata['password_sha1'] = passwd(password)
userdata['password_sha1'] = sha1(password.encode("utf-8"))
userdata['port'] = port
userdata['servername'] = servername
with open("jupyter_notebook_config.temp.py", "w") as f:
print(nbconfig.render(**userdata), file=f)
@ -34,4 +38,5 @@ with open("jupyter_notebook_config.temp.py", "w") as f:
os.system(f"sudo service jupyterlab@{username} restart")
print(f"New password: {password}")
print("Done!")

Loading…
Cancel
Save