Index: acct_mgr/pwhash.py =================================================================== --- acct_mgr/pwhash.py (revision 5833) +++ acct_mgr/pwhash.py (working copy) @@ -10,12 +10,12 @@ # Author: Matthew Good from binascii import hexlify -import md5, sha +import hashlib +import base64 from trac.core import * from trac.config import Option -from md5crypt import md5crypt from acct_mgr.util import urandom class IPasswordHashMethod(Interface): @@ -57,7 +57,7 @@ # check for the availability of the "crypt" module for checking passwords on # Unix-like platforms -# MD5 is still used when adding/updating passwords +# MD5 is still used when adding/updating passwords with htdigest try: from crypt import crypt except ImportError: @@ -72,22 +72,14 @@ return s def htpasswd(password, salt_=None): -# TODO need unit test of generating new hash - if salt_ is None: - salt_ = salt() - if crypt is None: - salt_ = '$apr1$' + salt_ - if salt_.startswith('$apr1$'): - return md5crypt(password, salt_[6:].split('$')[0], '$apr1$') - elif salt_.startswith('{SHA}'): - return '{SHA}' + sha.new(password).digest().encode('base64')[:-1] - elif crypt is None: - # crypt passwords are only supported on Unix-like systems - raise NotImplementedError('The "crypt" module is unavailable ' - 'on this platform.') - else: - return crypt(password, salt_) + """ + Modified to make compatible with Jira + """ + digested = hashlib.sha512(password).digest() + encoded = base64.b64encode(digested) + + return encoded.encode('utf8') def htdigest(user, realm, password): p = ':'.join([user, realm, password]) - return md5.new(p).hexdigest() + return hashlib.md5(p).hexdigest()