VMM/password: Added function extract_scheme(). v0.7.x
authorPascal Volk <user@localhost.localdomain.org>
Sun, 16 Feb 2014 23:07:30 +0000
branchv0.7.x
changeset 731 77561c118f42
parent 730 d3a246067e8f
child 734 8167ba72235c
VMM/password: Added function extract_scheme().
VirtualMailManager/password.py
--- a/VirtualMailManager/password.py	Sat Feb 15 23:38:27 2014 +0000
+++ b/VirtualMailManager/password.py	Sun Feb 16 23:07:30 2014 +0000
@@ -13,9 +13,11 @@
         random_password = randompw()
         scheme, encoding = verify_scheme(scheme)
         schemes, encodings = list_schemes()
+        scheme = extract_scheme(hashed_password)
 """
 
 import hashlib
+import re
 
 from base64 import b64encode
 from binascii import b2a_hex
@@ -309,6 +311,17 @@
 }
 
 
+def extract_scheme(password_hash):
+    """Returns the extracted password scheme from *password_hash*.
+
+    If the scheme couldn't be extracted, **None** will be returned.
+    """
+    scheme = re.match(r'^\{([^\}]{3,37})\}', password_hash)
+    if scheme:
+        return scheme.groups()[0]
+    return scheme
+
+
 def list_schemes():
     """Returns the tuple (schemes, encodings).