##// END OF EJS Templates
Fix password hashing for Python 3...
Thomas Kluyver -
Show More
@@ -12,6 +12,7 b' import random'
12 12 # Our own
13 13 from IPython.core.error import UsageError
14 14 from IPython.testing.skipdoctest import skip_doctest
15 from IPython.utils.py3compat import cast_bytes, str_to_bytes
15 16
16 17 #-----------------------------------------------------------------------------
17 18 # Globals
@@ -66,7 +67,7 b" def passwd(passphrase=None, algorithm='sha1'):"
66 67
67 68 h = hashlib.new(algorithm)
68 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 72 return ':'.join((algorithm, salt, h.hexdigest()))
72 73
@@ -112,6 +113,6 b' def passwd_check(hashed_passphrase, passphrase):'
112 113 if len(pw_digest) == 0:
113 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 118 return h.hexdigest() == pw_digest
General Comments 0
You need to be logged in to leave comments. Login now