Changeset 1517

Show
Ignore:
Timestamp:
11/10/06 15:40:14 (2 years ago)
Author:
mgood
Message:

AccountManagerPlugin:

write htpasswd entries using the crypt module when possible (fixes #883)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • accountmanagerplugin/0.10/acct_mgr/htfile.py

    r1502 r1517  
    3030    from crypt import crypt 
    3131except ImportError: 
    32     def crypt(password, salt): 
    33         raise NotImplementedError('The "crypt" module is unavailable on this ' 
    34                                   'platform.  Only MD5 passwords (starting ' 
    35                                   'with "$apr1$") are supported in the ' 
    36                                   'htpasswd file.') 
     32    crypt = None 
    3733 
    3834# os.urandom was added in Python 2.4 
     
    156152 
    157153    def userline(self, user, password): 
    158         return self.prefix(user) + md5crypt(password, salt(), '$apr1$') 
     154        if crypt is None: 
     155            return self.prefix(user) + md5crypt(password, salt(), '$apr1$') 
     156        else: 
     157            return self.prefix(user) + crypt(password, salt()) 
    159158 
    160159    def _check_userline(self, password, prefix, suffix): 
     
    165164            return (suffix[5:] == 
    166165                    sha.new(password).digest().encode('base64')[:-1]) 
     166        elif crypt is None: 
     167            # crypt passwords are only supported on Unix-like systems 
     168            raise NotImplementedError('The "crypt" module is unavailable ' 
     169                                      'on this platform.  Only MD5 ' 
     170                                      'passwords (starting with "$apr1$") ' 
     171                                      'are supported in the htpasswd file.') 
    167172        else: 
    168             # crypt passwords are only supported on Unix-like systems 
    169             # a dummy crypt implementation is provided above that throws 
    170             # a NotImplementedError if the crypt module is unavailable 
    171173            return suffix == crypt(password, suffix[:2]) 
    172174 
  • accountmanagerplugin/0.9/acct_mgr/htfile.py

    r1128 r1517  
    2929    from crypt import crypt 
    3030except ImportError: 
    31     def crypt(password, salt): 
    32         raise NotImplementedError('The "crypt" module is unavailable on this ' 
    33                                   'platform.  Only MD5 passwords (starting ' 
    34                                   'with "$apr1$") are supported in the ' 
    35                                   'htpasswd file.') 
     31    crypt = None 
    3632 
    3733# os.urandom was added in Python 2.4 
     
    150146 
    151147    def userline(self, user, password): 
    152         return self.prefix(user) + md5crypt(password, salt(), '$apr1$') 
     148        if crypt is None: 
     149            return self.prefix(user) + md5crypt(password, salt(), '$apr1$') 
     150        else: 
     151            return self.prefix(user) + crypt(password, salt()) 
    153152 
    154153    def _check_userline(self, password, prefix, suffix): 
     
    159158            return (suffix[5:] == 
    160159                    sha.new(password).digest().encode('base64')[:-1]) 
     160        elif crypt is None: 
     161            # crypt passwords are only supported on Unix-like systems 
     162            raise NotImplementedError('The "crypt" module is unavailable ' 
     163                                      'on this platform.  Only MD5 ' 
     164                                      'passwords (starting with "$apr1$") ' 
     165                                      'are supported in the htpasswd file.') 
    161166        else: 
    162             # crypt passwords are only supported on Unix-like systems 
    163             # a dummy crypt implementation is provided above that throws 
    164             # a NotImplementedError if the crypt module is unavailable 
    165167            return suffix == crypt(password, suffix[:2]) 
    166168 
  • accountmanagerplugin/trunk/acct_mgr/htfile.py

    r1128 r1517  
    3030    from crypt import crypt 
    3131except ImportError: 
    32     def crypt(password, salt): 
    33         raise NotImplementedError('The "crypt" module is unavailable on this ' 
    34                                   'platform.  Only MD5 passwords (starting ' 
    35                                   'with "$apr1$") are supported in the ' 
    36                                   'htpasswd file.') 
     32    crypt = None 
    3733 
    3834# os.urandom was added in Python 2.4 
     
    156152 
    157153    def userline(self, user, password): 
    158         return self.prefix(user) + md5crypt(password, salt(), '$apr1$') 
     154        if crypt is None: 
     155            return self.prefix(user) + md5crypt(password, salt(), '$apr1$') 
     156        else: 
     157            return self.prefix(user) + crypt(password, salt()) 
    159158 
    160159    def _check_userline(self, password, prefix, suffix): 
     
    165164            return (suffix[5:] == 
    166165                    sha.new(password).digest().encode('base64')[:-1]) 
     166        elif crypt is None: 
     167            # crypt passwords are only supported on Unix-like systems 
     168            raise NotImplementedError('The "crypt" module is unavailable ' 
     169                                      'on this platform.  Only MD5 ' 
     170                                      'passwords (starting with "$apr1$") ' 
     171                                      'are supported in the htpasswd file.') 
    167172        else: 
    168             # crypt passwords are only supported on Unix-like systems 
    169             # a dummy crypt implementation is provided above that throws 
    170             # a NotImplementedError if the crypt module is unavailable 
    171173            return suffix == crypt(password, suffix[:2]) 
    172174