Commits

Denis Darii committed ac592fd

improved password clean def

Comments (0)

Files changed (1)

dynamic_password/utils.py

+import re
 from datetime import datetime
-import difflib
 from django.conf import settings
 
 
 def get_clean_password(raw_password):
-    clean_password = ''
     password_pattern = getattr(settings, 'DYNAMIC_PASSWORD_PATTERN', '<PASSWORD>')
     now = datetime.now()
-    dynamic_password = now.strftime(password_pattern)
-    diff = difflib.SequenceMatcher(None, raw_password, dynamic_password.replace('<PASSWORD>', ''))
-    for block in diff.get_matching_blocks():
-        if block[2]:
-            clean_password += raw_password[0:block[0]]
-    return clean_password
+    dynamic_password = now.strftime(password_pattern).replace('<PASSWORD>', '(?P<password>.*)')
+    match_result = re.match(dynamic_password, raw_password)
+    if match_result:
+        return match_result.group('password')
+    return ''