diff --git a/src/mibew/libs/config.php b/src/mibew/libs/config.php index 3b45e7b3..87ad167b 100644 --- a/src/mibew/libs/config.php +++ b/src/mibew/libs/config.php @@ -54,4 +54,6 @@ $default_locale = "en"; /* if user does not provide known lang */ */ $use_open_basedir_protection = false; +require_once('password-policy.php'); + ?> \ No newline at end of file diff --git a/src/mibew/libs/password-policy.php b/src/mibew/libs/password-policy.php new file mode 100644 index 00000000..7aa04554 --- /dev/null +++ b/src/mibew/libs/password-policy.php @@ -0,0 +1,29 @@ += 16) { + return true; + } + + $character_classes = 0; + if (preg_match('/[A-Z]/', $pwd)) $character_classes++; + if (preg_match('/[a-z]/', $pwd)) $character_classes++; + if (preg_match('/[0-9]/', $pwd)) $character_classes++; + if (preg_match('/[^A-Za-z0-9]/', $pwd)) $character_classes++; + + if ($character_classes >= 3) { + return true; + } + return false; +} + +?> diff --git a/src/mibew/locales/en/properties b/src/mibew/locales/en/properties index 73d823ba..ea979e81 100644 --- a/src/mibew/locales/en/properties +++ b/src/mibew/locales/en/properties @@ -248,6 +248,7 @@ menu.translate=Localize menu.updates.content=Check for news and updates. menu.updates=Updates my_settings.error.password_match=Entered passwords do not match +my_settings.error.password_policy=Password is too simple no_such_operator=No such Operator notification.back_to_list=Back to the list notification.intro=Contents of sent notification. diff --git a/src/mibew/operator/operator.php b/src/mibew/operator/operator.php index 348c26eb..eddf308d 100644 --- a/src/mibew/operator/operator.php +++ b/src/mibew/operator/operator.php @@ -69,6 +69,11 @@ if (isset($_POST['login']) && isset($_POST['password'])) { if ($password != $passwordConfirm) $errors[] = getlocal("my_settings.error.password_match"); + + if ($password_policy) { + if (!call_user_func($password_policy, $password)) + $errors[] = getlocal("my_settings.error.password_policy"); + } $existing_operator = operator_by_login($login); if ((!$opId && $existing_operator) || @@ -147,4 +152,4 @@ prepare_menu($operator); setup_operator_settings_tabs($opId, 0); start_html_output(); require('../view/agent.php'); -?> \ No newline at end of file +?>