VirtualMailManager/password.py
branchv0.7.x
changeset 731 77561c118f42
parent 725 300b76de5ad0
equal deleted inserted replaced
730:d3a246067e8f 731:77561c118f42
    11 
    11 
    12         hashed_password = pwhash(password[, scheme][, user])
    12         hashed_password = pwhash(password[, scheme][, user])
    13         random_password = randompw()
    13         random_password = randompw()
    14         scheme, encoding = verify_scheme(scheme)
    14         scheme, encoding = verify_scheme(scheme)
    15         schemes, encodings = list_schemes()
    15         schemes, encodings = list_schemes()
       
    16         scheme = extract_scheme(hashed_password)
    16 """
    17 """
    17 
    18 
    18 import hashlib
    19 import hashlib
       
    20 import re
    19 
    21 
    20 from base64 import b64encode
    22 from base64 import b64encode
    21 from binascii import b2a_hex
    23 from binascii import b2a_hex
    22 from crypt import crypt
    24 from crypt import crypt
    23 from random import SystemRandom
    25 from random import SystemRandom
   307     'SSHA256': (_ssha256_hash, 0x10200a04),
   309     'SSHA256': (_ssha256_hash, 0x10200a04),
   308     'SSHA512': (_ssha512_hash, 0x20000b03),
   310     'SSHA512': (_ssha512_hash, 0x20000b03),
   309 }
   311 }
   310 
   312 
   311 
   313 
       
   314 def extract_scheme(password_hash):
       
   315     """Returns the extracted password scheme from *password_hash*.
       
   316 
       
   317     If the scheme couldn't be extracted, **None** will be returned.
       
   318     """
       
   319     scheme = re.match(r'^\{([^\}]{3,37})\}', password_hash)
       
   320     if scheme:
       
   321         return scheme.groups()[0]
       
   322     return scheme
       
   323 
       
   324 
   312 def list_schemes():
   325 def list_schemes():
   313     """Returns the tuple (schemes, encodings).
   326     """Returns the tuple (schemes, encodings).
   314 
   327 
   315     `schemes` is an iterator for all supported password schemes (depends on
   328     `schemes` is an iterator for all supported password schemes (depends on
   316     the used Dovecot version and features of the libc).
   329     the used Dovecot version and features of the libc).