Show More
@@ -210,11 +210,9 b' class NotebookApp(BaseIPythonApplication):' | |||
|
210 | 210 | password = Unicode(u'', config=True, |
|
211 | 211 | help="""Hashed password to use for web authentication. |
|
212 | 212 | |
|
213 |
To generate, |
|
|
213 | To generate, type in a python/IPython shell: | |
|
214 | 214 | |
|
215 | from IPython.lib import passwd | |
|
216 | ||
|
217 | passwd('mypassphrase') | |
|
215 | from IPython.lib import passwd; passwd() | |
|
218 | 216 | |
|
219 | 217 | The string should be of the form type:salt:hashed-password. |
|
220 | 218 | """ |
@@ -1,17 +1,31 b'' | |||
|
1 | 1 | """ |
|
2 | 2 | Password generation for the IPython notebook. |
|
3 | 3 | """ |
|
4 | ||
|
4 | #----------------------------------------------------------------------------- | |
|
5 | # Imports | |
|
6 | #----------------------------------------------------------------------------- | |
|
7 | # Stdlib | |
|
8 | import getpass | |
|
5 | 9 | import hashlib |
|
6 | 10 | import random |
|
7 | import getpass | |
|
8 | 11 | |
|
12 | # Our own | |
|
9 | 13 | from IPython.core.error import UsageError |
|
14 | from IPython.testing.skipdoctest import skip_doctest | |
|
15 | ||
|
16 | #----------------------------------------------------------------------------- | |
|
17 | # Globals | |
|
18 | #----------------------------------------------------------------------------- | |
|
10 | 19 | |
|
11 | 20 | # Length of the salt in nr of hex chars, which implies salt_len * 4 |
|
12 | 21 | # bits of randomness. |
|
13 | 22 | salt_len = 12 |
|
14 | 23 | |
|
24 | #----------------------------------------------------------------------------- | |
|
25 | # Functions | |
|
26 | #----------------------------------------------------------------------------- | |
|
27 | ||
|
28 | @skip_doctest | |
|
15 | 29 | def passwd(passphrase=None, algorithm='sha1'): |
|
16 | 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 | 71 | return ':'.join((algorithm, salt, h.hexdigest())) |
|
58 | 72 | |
|
73 | ||
|
59 | 74 | def passwd_check(hashed_passphrase, passphrase): |
|
60 | 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 | 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 | 94 | ...: 'mypassword') |
|
80 | 95 | Out[2]: True |
|
81 | 96 | |
|
82 | In [3]: passwd_check('sha1:7cf3:b7d6da294ea9592a9480c8f52e63cd42cfb9dd12', | |
|
97 | In [3]: passwd_check('sha1:0e112c3ddfce:a68df677475c2b47b6e86d0467eec97ac5f4b85a', | |
|
83 | 98 | ...: 'anotherpassword') |
|
84 | 99 | Out[3]: False |
|
85 | 100 |
General Comments 0
You need to be logged in to leave comments.
Login now