##// END OF EJS Templates
Try to get password from user three times.
Stefan van der Walt -
Show More
@@ -10,7 +10,7 b' import getpass'
10 # bits of randomness.
10 # bits of randomness.
11 salt_len = 12
11 salt_len = 12
12
12
13 def passwd(passphrase='', algorithm='sha1'):
13 def passwd(passphrase=None, algorithm='sha1'):
14 """Generate hashed password and salt for use in notebook configuration.
14 """Generate hashed password and salt for use in notebook configuration.
15
15
16 In the notebook configuration, set `c.NotebookApp.password` to
16 In the notebook configuration, set `c.NotebookApp.password` to
@@ -36,13 +36,17 b" def passwd(passphrase='', algorithm='sha1'):"
36 Out[1]: 'sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12'
36 Out[1]: 'sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12'
37
37
38 """
38 """
39 if not passphrase:
39 if passphrase is None:
40 p0 = getpass.getpass('Enter password: ')
40 for i in range(3):
41 p1 = getpass.getpass('Verify password: ')
41 p0 = getpass.getpass('Enter password: ')
42 if (p0 == p1):
42 p1 = getpass.getpass('Verify password: ')
43 passphrase = p0
43 if p0 == p1:
44 passphrase = p0
45 break
46 else:
47 print('Passwords do not match.')
44 else:
48 else:
45 raise ValueError('Passwords did not match.')
49 raise ValueError('No matching passwords found. Giving up.')
46
50
47 h = hashlib.new(algorithm)
51 h = hashlib.new(algorithm)
48 salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len)
52 salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len)
General Comments 0
You need to be logged in to leave comments. Login now