diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py index c2d0b6abb0..94618948e3 100644 --- a/frappe/core/doctype/user/user.py +++ b/frappe/core/doctype/user/user.py @@ -49,7 +49,9 @@ class User(Document): self.__new_password = self.new_password self.new_password = "" - self.password_strength_test() + if not frappe.flags.in_test: + self.password_strength_test() + if self.name not in STANDARD_USERS: self.validate_email_type(self.email) self.validate_email_type(self.name) @@ -409,7 +411,8 @@ class User(Document): self.username = "" def password_strength_test(self): - if self.__new_password: + """ test password strength """ + if frappe.db.get_single_value("System Settings", "enable_password_policy") and self.__new_password: user_data = (self.first_name, self.middle_name, self.last_name, self.email, self.birth_date) result = test_password_strength(self.__new_password, '', None, user_data) @@ -869,4 +872,4 @@ def handle_password_test_fail(result): suggestions = result['feedback']['suggestions'][0] if result['feedback']['suggestions'] else '' warning = result['feedback']['warning'] if 'warning' in result['feedback'] else '' suggestions += "
" + _("Hint: Include symbols, numbers and capital letters in the password") + '
' - frappe.throw(_('Invalid Password: ' + ' '.join([warning, suggestions]))) \ No newline at end of file + frappe.throw(_('Invalid Password: ' + ' '.join([warning, suggestions]))) diff --git a/frappe/utils/password_strength.py b/frappe/utils/password_strength.py index 215ba1cba0..75d0f00013 100644 --- a/frappe/utils/password_strength.py +++ b/frappe/utils/password_strength.py @@ -2,8 +2,10 @@ # MIT License. See license.txt from __future__ import unicode_literals -from frappe import _ + import zxcvbn +import frappe +from frappe import _ def test_password_strength(password, user_inputs=None): '''Wrapper around zxcvbn.password_strength''' @@ -35,12 +37,14 @@ def get_feedback (score, sequence): """ Returns the feedback dictionary consisting of ("warning","suggestions") for the given sequences. """ + minimum_password_score = frappe.db.get_single_value("System Settings", "minimum_password_score") + global default_feedback # Starting feedback if len(sequence) == 0: return default_feedback # No feedback if score is good or great - if score > 2: + if score > minimum_password_score: return dict({"warning": "","suggestions": []}) # Tie feedback to the longest match for longer sequences longest_match = max(sequence, key=lambda x: len(x['token'])) @@ -132,7 +136,9 @@ def get_match_feedback(match, is_sole_match): "date": fun_date, "year": fun_date } - return(patterns[match['pattern']]()) + pattern_fn = patterns.get(match['pattern']) + if pattern_fn: + return(pattern_fn()) def get_dictionary_match_feedback(match, is_sole_match): """