* Fixed issue #frappe WN-SUP25323 for password strength error * [hotfix] fixes in password strength test * [hotfix] ignore password strength test in testsversion-14
@@ -49,7 +49,9 @@ class User(Document): | |||||
self.__new_password = self.new_password | self.__new_password = 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: | if self.name not in STANDARD_USERS: | ||||
self.validate_email_type(self.email) | self.validate_email_type(self.email) | ||||
self.validate_email_type(self.name) | self.validate_email_type(self.name) | ||||
@@ -409,7 +411,8 @@ class User(Document): | |||||
self.username = "" | self.username = "" | ||||
def password_strength_test(self): | 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) | 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) | 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 '' | suggestions = result['feedback']['suggestions'][0] if result['feedback']['suggestions'] else '' | ||||
warning = result['feedback']['warning'] if 'warning' in result['feedback'] else '' | warning = result['feedback']['warning'] if 'warning' in result['feedback'] else '' | ||||
suggestions += "<br>" + _("Hint: Include symbols, numbers and capital letters in the password") + '<br>' | suggestions += "<br>" + _("Hint: Include symbols, numbers and capital letters in the password") + '<br>' | ||||
frappe.throw(_('Invalid Password: ' + ' '.join([warning, suggestions]))) | |||||
frappe.throw(_('Invalid Password: ' + ' '.join([warning, suggestions]))) |
@@ -2,8 +2,10 @@ | |||||
# MIT License. See license.txt | # MIT License. See license.txt | ||||
from __future__ import unicode_literals | from __future__ import unicode_literals | ||||
from frappe import _ | |||||
import zxcvbn | import zxcvbn | ||||
import frappe | |||||
from frappe import _ | |||||
def test_password_strength(password, user_inputs=None): | def test_password_strength(password, user_inputs=None): | ||||
'''Wrapper around zxcvbn.password_strength''' | '''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. | 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 | global default_feedback | ||||
# Starting feedback | # Starting feedback | ||||
if len(sequence) == 0: | if len(sequence) == 0: | ||||
return default_feedback | return default_feedback | ||||
# No feedback if score is good or great | # No feedback if score is good or great | ||||
if score > 2: | |||||
if score > minimum_password_score: | |||||
return dict({"warning": "","suggestions": []}) | return dict({"warning": "","suggestions": []}) | ||||
# Tie feedback to the longest match for longer sequences | # Tie feedback to the longest match for longer sequences | ||||
longest_match = max(sequence, key=lambda x: len(x['token'])) | 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, | "date": fun_date, | ||||
"year": 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): | def get_dictionary_match_feedback(match, is_sole_match): | ||||
""" | """ | ||||