VirtualMailManager/password.py
branchv0.6.x
changeset 289 142f188f7552
parent 287 1e77dd639fa3
child 290 e2785e04f92e
equal deleted inserted replaced
288:01cb71c1ae33 289:142f188f7552
   138     rounds = cfg_dget('misc.crypt_blowfish_rounds')
   138     rounds = cfg_dget('misc.crypt_blowfish_rounds')
   139     if rounds < 4:
   139     if rounds < 4:
   140         rounds = 4
   140         rounds = 4
   141     elif rounds > 31:
   141     elif rounds > 31:
   142         rounds = 31
   142         rounds = 31
   143     return '$2a$%02d$%s$' % (rounds, _get_salt(22))
   143     return '$2a$%02d$%s' % (rounds, _get_salt(22))
   144 
   144 
   145 
   145 
   146 def _get_crypt_shaxxx_salt(crypt_id):
   146 def _get_crypt_shaxxx_salt(crypt_id):
   147     """Generates a salt for crypt using the SHA-256 or SHA-512 encryption
   147     """Generates a salt for crypt using the SHA-256 or SHA-512 encryption
   148     method.
   148     method.
   155         rounds = cfg_dget('misc.crypt_sha256_rounds')
   155         rounds = cfg_dget('misc.crypt_sha256_rounds')
   156     if rounds < 1000:
   156     if rounds < 1000:
   157         rounds = 1000
   157         rounds = 1000
   158     elif rounds > 999999999:
   158     elif rounds > 999999999:
   159         rounds = 999999999
   159         rounds = 999999999
   160     return '$%d$rounds=%d$%s$' % (crypt_id, rounds, _get_salt(16))
   160     return '$%d$rounds=%d$%s' % (crypt_id, rounds, _get_salt(16))
   161 
   161 
   162 
   162 
   163 def _crypt_hash(password, scheme, encoding):
   163 def _crypt_hash(password, scheme, encoding):
   164     """Generates (encoded) CRYPT/MD5/MD5-CRYPT hashes."""
   164     """Generates (encoded) CRYPT/MD5/MD5-CRYPT hashes."""
   165     if scheme == 'CRYPT':
   165     if scheme == 'CRYPT':
   170         elif CRYPT_SHA256 and cfg_dget('misc.crypt_sha256_rounds'):
   170         elif CRYPT_SHA256 and cfg_dget('misc.crypt_sha256_rounds'):
   171             salt = _get_crypt_shaxxx_salt(5)
   171             salt = _get_crypt_shaxxx_salt(5)
   172         else:
   172         else:
   173             salt = _get_salt(2)
   173             salt = _get_salt(2)
   174     else:
   174     else:
   175         salt = '$1$%s$' % _get_salt(8)
   175         salt = '$1$%s' % _get_salt(8)
   176     encrypted = crypt(password, salt)
   176     encrypted = crypt(password, salt)
   177     if encoding:
   177     if encoding:
   178         if encoding == 'HEX':
   178         if encoding == 'HEX':
   179             encrypted = encrypted.encode('hex')
   179             encrypted = encrypted.encode('hex')
   180         else:
   180         else: