Skip to content

Commit

Permalink
Explicitly set md5 digest function for hmac.
Browse files Browse the repository at this point in the history
Use sys.stdout.write instead of print operator.
  • Loading branch information
abbot committed Nov 13, 2016
1 parent 76c38c8 commit b44c7f2
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
11 changes: 6 additions & 5 deletions pwdhash.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#!/usr/bin/env python

import re
import hashlib
import hmac
import itertools

import re
import sys

def b64_hmac_md5(key, data):
"""
return base64-encoded HMAC-MD5 for key and data, with trailing '='
stripped.
"""
bdigest = hmac.HMAC(key, data).digest().encode('base64').strip()
bdigest = hmac.new(key, data, hashlib.md5).digest().encode('base64').strip()
return re.sub('=+$', '', bdigest)


Expand Down Expand Up @@ -176,9 +177,9 @@ def console_main():
pass

if copied_to_clipboard:
print "Password was copied to clipboard."
sys.stdout.write("Password was copied to clipboard.\n")
else:
print generated
sys.stdout.write(generated+"\n")

if __name__ == '__main__':
console_main()
5 changes: 4 additions & 1 deletion pwdhash_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ def test_generate(self):

def test_applyconstraints(self):
self.assertEqual(pwdhash.apply_constraints("5vY9jidbW9wPvvubi1ilRw", 3, False),
"9FBo")
"9FBo")

if __name__ == '__main__':
unittest.main()

0 comments on commit b44c7f2

Please sign in to comment.