INSERT INTO `ohrm_config` (`property`, `value`) VALUES
('authentication.status', 'Enable'),
('authentication.user_can_reset', 'off'),
('authentication.enable_captcha', 'on'),
('authentication.block_access', 'on'),
('authentication.attempts_for_captcha', '3'),
('authentication.attempts_for_block', '10'),
('authentication.blocked_duration', '1:00:00'),
('authentication.secondary_password_enabled', 'off'),
('authentication.password_expiration_enabled', 'on'),
('authentication.num_of_months_for_password_expiration', '3'),
('authentication.admin_can_reset', 'off'),
('authentication.notify_employee_after_user_creation', 'off'),
('authentication.enforce_password_strength', 'on'),
('authentication.default_required_password_strength', 'strong');

SET @auth_xml = (SELECT value FROM `ohrm_config` WHERE `property`='security_authentication');

UPDATE `ohrm_config`
SET `value` = 'on'
WHERE `property`= 'authentication.user_can_reset'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//Reset')),'on') = 0;

UPDATE `ohrm_config`
SET `value` = TRIM(ExtractValue(@auth_xml, '//AttemptsToCaptcha'))
WHERE `property`= 'authentication.attempts_for_captcha'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//Captcha')),'on') = 0
AND CAST(TRIM(ExtractValue(@auth_xml, '//AttemptsToCaptcha')) AS UNSIGNED) < 3;

UPDATE `ohrm_config`
SET `value` = TRIM(ExtractValue(@auth_xml, '//AttemptsToBlock'))
WHERE `property`= 'authentication.attempts_for_block'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//Block')),'on') = 0
AND CAST(TRIM(ExtractValue(@auth_xml, '//AttemptsToBlock')) AS UNSIGNED) < 10;

UPDATE `ohrm_config`
SET `value` = TRIM(ExtractValue(@auth_xml, '//DisabledTime'))
WHERE `property`= 'authentication.blocked_duration'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//Block')),'on') = 0
AND TIME_TO_SEC(TRIM(ExtractValue(@auth_xml, '//DisabledTime'))) > TIME_TO_SEC('1:00:00');

UPDATE `ohrm_config`
SET `value` = 'on'
WHERE `property`= 'authentication.secondary_password_enabled'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//SecondaryPassword')),'on') = 0;

UPDATE `ohrm_config`
SET `value` = TRIM(ExtractValue(@auth_xml, '//PasswordExpirationPeriod'))
WHERE `property`= 'authentication.num_of_months_for_password_expiration'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//PasswordExpiration')),'on') = 0
AND CAST(TRIM(ExtractValue(@auth_xml, '//PasswordExpirationPeriod')) AS UNSIGNED) < 3;

UPDATE `ohrm_config`
SET `value` = 'on'
WHERE `property`= 'authentication.admin_can_reset'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//AdminReset')),'on') = 0;

UPDATE `ohrm_config`
SET `value` = 'on'
WHERE `property`= 'authentication.notify_employee_after_user_creation'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//AutoReset')),'on') = 0;

UPDATE `ohrm_config`
SET `value` = 'strongest'
WHERE `property`= 'authentication.default_required_password_strength'
AND STRCMP(TRIM(ExtractValue(@auth_xml, '//PasswordStrengthEnforced')),'on') = 0
AND CAST(TRIM(ExtractValue(@auth_xml, '//RequiredPasswordStrength')) AS UNSIGNED) = 5;

DELETE FROM `ohrm_config` WHERE `property` = 'security_authentication';