##// END OF EJS Templates
Fix failing doctests and post correct example of passwd() usage.
Fernando Perez -
Show More
@@ -210,11 +210,9 b' class NotebookApp(BaseIPythonApplication):'
210 password = Unicode(u'', config=True,
210 password = Unicode(u'', config=True,
211 help="""Hashed password to use for web authentication.
211 help="""Hashed password to use for web authentication.
212
212
213 To generate, do:
213 To generate, type in a python/IPython shell:
214
214
215 from IPython.lib import passwd
215 from IPython.lib import passwd; passwd()
216
217 passwd('mypassphrase')
218
216
219 The string should be of the form type:salt:hashed-password.
217 The string should be of the form type:salt:hashed-password.
220 """
218 """
@@ -1,17 +1,31 b''
1 """
1 """
2 Password generation for the IPython notebook.
2 Password generation for the IPython notebook.
3 """
3 """
4
4 #-----------------------------------------------------------------------------
5 # Imports
6 #-----------------------------------------------------------------------------
7 # Stdlib
8 import getpass
5 import hashlib
9 import hashlib
6 import random
10 import random
7 import getpass
8
11
12 # Our own
9 from IPython.core.error import UsageError
13 from IPython.core.error import UsageError
14 from IPython.testing.skipdoctest import skip_doctest
15
16 #-----------------------------------------------------------------------------
17 # Globals
18 #-----------------------------------------------------------------------------
10
19
11 # Length of the salt in nr of hex chars, which implies salt_len * 4
20 # Length of the salt in nr of hex chars, which implies salt_len * 4
12 # bits of randomness.
21 # bits of randomness.
13 salt_len = 12
22 salt_len = 12
14
23
24 #-----------------------------------------------------------------------------
25 # Functions
26 #-----------------------------------------------------------------------------
27
28 @skip_doctest
15 def passwd(passphrase=None, algorithm='sha1'):
29 def passwd(passphrase=None, algorithm='sha1'):
16 """Generate hashed password and salt for use in notebook configuration.
30 """Generate hashed password and salt for use in notebook configuration.
17
31
@@ -56,6 +70,7 b" def passwd(passphrase=None, algorithm='sha1'):"
56
70
57 return ':'.join((algorithm, salt, h.hexdigest()))
71 return ':'.join((algorithm, salt, h.hexdigest()))
58
72
73
59 def passwd_check(hashed_passphrase, passphrase):
74 def passwd_check(hashed_passphrase, passphrase):
60 """Verify that a given passphrase matches its hashed version.
75 """Verify that a given passphrase matches its hashed version.
61
76
@@ -75,11 +90,11 b' def passwd_check(hashed_passphrase, passphrase):'
75 --------
90 --------
76 In [1]: from IPython.lib.security import passwd_check
91 In [1]: from IPython.lib.security import passwd_check
77
92
78 In [2]: passwd_check('sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12',
93 In [2]: passwd_check('sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a',
79 ...: 'mypassword')
94 ...: 'mypassword')
80 Out[2]: True
95 Out[2]: True
81
96
82 In [3]: passwd_check('sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12',
97 In [3]: passwd_check('sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a',
83 ...: 'anotherpassword')
98 ...: 'anotherpassword')
84 Out[3]: False
99 Out[3]: False
85
100
General Comments 0
You need to be logged in to leave comments. Login now