diff --git a/notebook/auth/login.py b/notebook/auth/login.py index dc624fa2c..2478fc96a 100644 --- a/notebook/auth/login.py +++ b/notebook/auth/login.py @@ -4,6 +4,7 @@ # Distributed under the terms of the Modified BSD License. import re +import os try: from urllib.parse import urlparse # Py 3 @@ -13,7 +14,7 @@ import uuid from tornado.escape import url_escape -from ..auth.security import passwd_check +from .security import passwd_check, set_password from ..base.handlers import IPythonHandler @@ -72,16 +73,26 @@ class LoginHandler(IPythonHandler): def post(self): typed_password = self.get_argument('password', default=u'') + new_password = self.get_argument('new_password', default=u'') + + + if self.get_login_available(self.settings): - if self.passwd_check(self.hashed_password, typed_password): + if self.passwd_check(self.hashed_password, typed_password) and not new_password: self.set_login_cookie(self, uuid.uuid4().hex) elif self.token and self.token == typed_password: self.set_login_cookie(self, uuid.uuid4().hex) + if self.new_password: + config_dir = self.settings.get('config_dir') + config_file = os.path.join(config_dir, 'jupyter_notebook_config.json') + set_password(new_password, config_file=config_file) + self.log.info("Wrote hashed password to %s" % config_file) else: self.set_status(401) - self._render(message={'error': 'Invalid password'}) + self._render(message={'error': 'Invalid credentials'}) return + next_url = self.get_argument('next', default=self.base_url) self._redirect_safe(next_url) diff --git a/notebook/templates/login.html b/notebook/templates/login.html index 75aee8de7..c30af5acf 100644 --- a/notebook/templates/login.html +++ b/notebook/templates/login.html @@ -85,6 +85,22 @@ http://localhost:8888/?token=c8de56fa... :: /Users/you/notebooks

Cookies are required for authenticated access to notebooks.

+

{% trans %}Setup a Password{% endtrans %}

+

You can setup a password by entering your token and a new password + on the fields below:

+
+ {{ xsrf_form_html() | safe }} +
+ +
+
+ +
+
+ +
+
{% endblock token_message %}