Show More
@@ -12,6 +12,7 b' import random' | |||||
12 | # Our own |
|
12 | # Our own | |
13 | from IPython.core.error import UsageError |
|
13 | from IPython.core.error import UsageError | |
14 | from IPython.testing.skipdoctest import skip_doctest |
|
14 | from IPython.testing.skipdoctest import skip_doctest | |
|
15 | from IPython.utils.py3compat import cast_bytes, str_to_bytes | |||
15 |
|
16 | |||
16 | #----------------------------------------------------------------------------- |
|
17 | #----------------------------------------------------------------------------- | |
17 | # Globals |
|
18 | # Globals | |
@@ -66,7 +67,7 b" def passwd(passphrase=None, algorithm='sha1'):" | |||||
66 |
|
67 | |||
67 | h = hashlib.new(algorithm) |
|
68 | h = hashlib.new(algorithm) | |
68 | salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len) |
|
69 | salt = ('%0' + str(salt_len) + 'x') % random.getrandbits(4 * salt_len) | |
69 | h.update(passphrase + salt) |
|
70 | h.update(cast_bytes(passphrase, 'utf-8') + str_to_bytes(salt, 'ascii')) | |
70 |
|
71 | |||
71 | return ':'.join((algorithm, salt, h.hexdigest())) |
|
72 | return ':'.join((algorithm, salt, h.hexdigest())) | |
72 |
|
73 | |||
@@ -112,6 +113,6 b' def passwd_check(hashed_passphrase, passphrase):' | |||||
112 | if len(pw_digest) == 0: |
|
113 | if len(pw_digest) == 0: | |
113 | return False |
|
114 | return False | |
114 |
|
115 | |||
115 | h.update(passphrase + salt) |
|
116 | h.update(cast_bytes(passphrase, 'utf-8') + str_to_bytes(salt, 'ascii')) | |
116 |
|
117 | |||
117 | return h.hexdigest() == pw_digest |
|
118 | return h.hexdigest() == pw_digest |
General Comments 0
You need to be logged in to leave comments.
Login now