patch to enforce password policy

--HG--
extra : source : 98986452d02ff23ce833850d268e705c6b7b172f
This commit is contained in:
Toby Inkster 2014-03-13 16:13:48 +00:00
parent 2ff5ea3fb6
commit 5061949f94
4 changed files with 38 additions and 1 deletions

View File

@ -54,4 +54,6 @@ $default_locale = "en"; /* if user does not provide known lang */
*/ */
$use_open_basedir_protection = false; $use_open_basedir_protection = false;
require_once('password-policy.php');
?> ?>

View File

@ -0,0 +1,29 @@
<?php
/*
* You can set this to a different value.
* See http://www.php.net/manual/en/language.types.callable.php
*/
$password_policy = 'standard_password_policy';
function standard_password_policy ($pwd) {
if (strlen($pwd) < 8) {
return false;
}
if (strlen($pwd) >= 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;
}
?>

View File

@ -248,6 +248,7 @@ menu.translate=Localize
menu.updates.content=Check for news and updates. menu.updates.content=Check for news and updates.
menu.updates=Updates menu.updates=Updates
my_settings.error.password_match=Entered passwords do not match 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 no_such_operator=No such Operator
notification.back_to_list=Back to the list notification.back_to_list=Back to the list
notification.intro=Contents of sent notification. notification.intro=Contents of sent notification.

View File

@ -69,6 +69,11 @@ if (isset($_POST['login']) && isset($_POST['password'])) {
if ($password != $passwordConfirm) if ($password != $passwordConfirm)
$errors[] = getlocal("my_settings.error.password_match"); $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); $existing_operator = operator_by_login($login);
if ((!$opId && $existing_operator) || if ((!$opId && $existing_operator) ||
@ -147,4 +152,4 @@ prepare_menu($operator);
setup_operator_settings_tabs($opId, 0); setup_operator_settings_tabs($opId, 0);
start_html_output(); start_html_output();
require('../view/agent.php'); require('../view/agent.php');
?> ?>