From a85b45e027b6d88fa24c468282cccfedb664ec4e Mon Sep 17 00:00:00 2001 From: David Coutadeur Date: Mon, 9 Sep 2024 19:34:09 +0200 Subject: [PATCH] update code to use functions from \Ltb\Ppolicy class (#968) --- htdocs/change.php | 2 +- htdocs/changecustompwdfield.php | 2 +- htdocs/checkentropy.php | 2 +- htdocs/index.php | 2 +- htdocs/resetbyquestions.php | 2 +- htdocs/resetbytoken.php | 2 +- lib/functions.inc.php | 35 --------------------------------- 7 files changed, 6 insertions(+), 41 deletions(-) diff --git a/htdocs/change.php b/htdocs/change.php index 07394018..b7c92514 100644 --- a/htdocs/change.php +++ b/htdocs/change.php @@ -159,7 +159,7 @@ # Check password strength #============================================================================== if ( !$result ) { - $result = \Ltb\Password::check_password_strength( $newpassword, $oldpassword, $pwd_policy_config, $login, $entry_array, $change_custompwdfield ); + $result = \Ltb\Ppolicy::check_password_strength( $newpassword, $oldpassword, $pwd_policy_config, $login, $entry_array, $change_custompwdfield ); } #============================================================================== diff --git a/htdocs/changecustompwdfield.php b/htdocs/changecustompwdfield.php index 1d5731ae..2e038a66 100644 --- a/htdocs/changecustompwdfield.php +++ b/htdocs/changecustompwdfield.php @@ -217,7 +217,7 @@ function set_default_value(&$variable, $defaultValue) # Check password strength #============================================================================== if ( !$result ) { - $result = \Ltb\Password::check_password_strength( $newcustompwd, $password, $custompwdfield['pwd_policy_config'], $login, $entry_array, $change_custompwdfield ); + $result = \Ltb\Ppolicy::check_password_strength( $newcustompwd, $password, $custompwdfield['pwd_policy_config'], $login, $entry_array, $change_custompwdfield ); } #============================================================================== diff --git a/htdocs/checkentropy.php b/htdocs/checkentropy.php index 47a4e55e..cf237f0f 100644 --- a/htdocs/checkentropy.php +++ b/htdocs/checkentropy.php @@ -4,7 +4,7 @@ // new password sent in the url, base64 encoded $newpass = htmlspecialchars($_POST["password"]); -$entropy_response = \Ltb\Password::checkEntropyJSON($newpass); +$entropy_response = \Ltb\Ppolicy::checkEntropyJSON($newpass); if ($debug) { error_log("checkEntropy: ".$entropy_response); } diff --git a/htdocs/index.php b/htdocs/index.php index e06aaada..5ecef4ca 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -303,7 +303,7 @@ if (isset($token)) { $smarty->assign('token', $token); } if (isset($use_captcha)) { $smarty->assign('use_captcha', $use_captcha); } -smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config); +\Ltb\Ppolicy::smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config); if (isset($custompwdindex)) { $smarty->assign('custompwdindex', $custompwdindex); diff --git a/htdocs/resetbyquestions.php b/htdocs/resetbyquestions.php index 332f15aa..92fcc1c1 100644 --- a/htdocs/resetbyquestions.php +++ b/htdocs/resetbyquestions.php @@ -220,7 +220,7 @@ # Check password strength if ( !$result ) { - $result = \Ltb\Password::check_password_strength( $newpassword, "", $pwd_policy_config, $login, $entry_array, $change_custompwdfield ); + $result = \Ltb\Ppolicy::check_password_strength( $newpassword, "", $pwd_policy_config, $login, $entry_array, $change_custompwdfield ); } # Change password diff --git a/htdocs/resetbytoken.php b/htdocs/resetbytoken.php index 8a162318..a50aef9d 100644 --- a/htdocs/resetbytoken.php +++ b/htdocs/resetbytoken.php @@ -153,7 +153,7 @@ # Check password strength if ( !$result ) { $entry_array = ldap_get_attributes($ldap, $entry); - $result = \Ltb\Password::check_password_strength( $newpassword, "", $pwd_policy_config, $login, $entry_array, $change_custompwdfield ); + $result = \Ltb\Ppolicy::check_password_strength( $newpassword, "", $pwd_policy_config, $login, $entry_array, $change_custompwdfield ); } # Change password diff --git a/lib/functions.inc.php b/lib/functions.inc.php index 352574fa..c1778ccc 100644 --- a/lib/functions.inc.php +++ b/lib/functions.inc.php @@ -503,38 +503,3 @@ function allowed_rate($login,$ip_addr,$rrl_config) { } return true; } - -function smarty_assign_variable($smarty, $pwd_policy_config) -{ - foreach ($pwd_policy_config as $param => $value) { - if( isset($value) ) - { - // only send password policy parameters - // of type string to smarty template - if( !is_array($value) ) - { - $smarty->assign($param, $value); - } - } - } -} - -function smarty_assign_ppolicy($smarty, $pwd_show_policy_pos, $pwd_show_policy, $result, $pwd_policy_config ) -{ - if (isset($pwd_show_policy_pos)) { - $smarty->assign('pwd_show_policy_pos', $pwd_show_policy_pos); - $smarty->assign('pwd_show_policy', $pwd_show_policy); - $smarty->assign('pwd_show_policy_onerror', true); - if ( $pwd_show_policy === "onerror" ) { - if ( !preg_match( "/tooshort|toobig|minlower|minupper|mindigit|minspecial|forbiddenchars|sameasold|notcomplex|sameaslogin|pwned|specialatends/" , $result) ) { - $smarty->assign('pwd_show_policy_onerror', false); - } else { - $smarty->assign('pwd_show_policy_onerror', true); - } - } - smarty_assign_variable($smarty, $pwd_policy_config); - - // send policy to a JSON object usable in javascript - $smarty->assign('json_policy', base64_encode(json_encode( $pwd_policy_config ))); - } -}