Repository: frappe/frappe

Issue:
Password Strength Policy Enhancement
Password Strength Policy Enhancement
In Security Settings, the Password Policy can be enabled(See image 1 below) and the password strength score can be set.
User will see helpful password validation messages when they set/change password.

Set Password Policy:
![system_settings](https://cloud.githubusercontent.com/assets/9530991/25556724/5ca4339a-2d34-11e7-8e5d-7af3a59c3b6c.png)

Prompt friendly message to user, based on the password policy:
![user password ploicy validation](https://cloud.githubusercontent.com/assets/9530991/25556721/5c80db48-2d34-11e7-8b29-3550a82bf546.png)

Reset Password Strength Validation fail based on Password Policy:
![reset_password_fail_policy_test](https://cloud.githubusercontent.com/assets/9530991/25556722/5c86472c-2d34-11e7-8ee7-684df8f482f0.png)

Reset Password Strength Validation pass based on Password Policy:
![reset_password_pass_policy_test](https://cloud.githubusercontent.com/assets/9530991/25556723/5c9e449e-2d34-11e7-9ad5-6dab209633ad.png)






Discussion:
Can you also add a few test cases?

Resolving patch:
diff --git a/frappe/core/doctype/user/user.py b/frappe/core/doctype/user/user.py
--- a/frappe/core/doctype/user/user.py
+++ b/frappe/core/doctype/user/user.py
@@ -545,9 +545,9 @@ def test_password_strength(new_password, key=None, old_password=None, user_data=
 		enable_password_policy = cint(frappe.db.get_single_value("System Settings", "enable_password_policy")) and True or False
 		minimum_password_score = cint(frappe.db.get_single_value("System Settings", "minimum_password_score")) or 0
 
-		password_policy_validation_passed = True
-		if enable_password_policy and result['score'] < minimum_password_score:
-			password_policy_validation_passed = False
+		password_policy_validation_passed = False
+		if result['score'] > minimum_password_score:
+			password_policy_validation_passed = True
 
 		result['feedback']['password_policy_validation_passed'] = password_policy_validation_passed
 


Test patch:
diff --git a/frappe/core/doctype/user/test_user.py b/frappe/core/doctype/user/test_user.py
--- a/frappe/core/doctype/user/test_user.py
+++ b/frappe/core/doctype/user/test_user.py
@@ -220,22 +220,26 @@ def test_deactivate_additional_users(self):
 		clear_limit('users')
 
 	def test_password_strength(self):
-		#Test Password without Password Strenth Policy
+		# Test Password without Password Strenth Policy
 		frappe.db.set_value("System Settings", "System Settings", "enable_password_policy", 0)
 		frappe.db.set_value("System Settings", "System Settings", "minimum_password_score", "")
 
-		# Should pass password strength test
+		# Score 0; should fail
 		result = test_password_strength("test_password")
+		self.assertEqual(result['feedback']['password_policy_validation_passed'], False)
+
+		# Score 1; should pass
+		result = test_password_strength("bee2ve")
 		self.assertEqual(result['feedback']['password_policy_validation_passed'], True)
 
 		# Test Password with Password Strenth Policy Set
 		frappe.db.set_value("System Settings", "System Settings", "enable_password_policy", 1)
 		frappe.db.set_value("System Settings", "System Settings", "minimum_password_score", 2)
 
-		#Should fail password strength test
-		result = test_password_strength("test_password")
+		# Score 1; should now fail
+		result = test_password_strength("bee2ve")
 		self.assertEqual(result['feedback']['password_policy_validation_passed'], False)
 
-		# Should pass password strength test
+		# Score 4; should pass
 		result = test_password_strength("Eastern_43A1W")
-		self.assertEqual(result['feedback']['password_policy_validation_passed'], True)
\ No newline at end of file
+		self.assertEqual(result['feedback']['password_policy_validation_passed'], True)