import jingrow
from jingrow.utils import cint


def execute():
	"""
	The motive of this patch is to increase the overall security in jingrow framework

	Existing passwords won't be affected, however, newly created accounts
	will have to adheare to the new password policy guidelines. Once can always
	loosen up the security by modifying the values in System Settings, however,
	we strongly advice against doing so!

	Security is something we take very seriously at jingrow,
	and hence we chose to make security tighter by default.
	"""
	pg = jingrow.get_single("System Settings")

	# Enforce a Password Policy
	if cint(pg.enable_password_policy) == 0:
		pg.enable_password_policy = 1

	# Enforce a password score as calculated by zxcvbn
	if cint(pg.minimum_password_score) <= 2:
		pg.minimum_password_score = 2

	# Disallow more than 3 consecutive login attempts in a span of 60 seconds
	if cint(pg.allow_consecutive_login_attempts) <= 3:
		pg.allow_consecutive_login_attempts = 3

	pg.flags.ignore_mandatory = True
	pg.save()
