Skip to content

Commit

Permalink
update code to use functions from \Ltb\Ppolicy class (#968)
Browse files Browse the repository at this point in the history
  • Loading branch information
David Coutadeur committed Sep 9, 2024
1 parent e0ca88a commit a85b45e
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 41 deletions.
2 changes: 1 addition & 1 deletion htdocs/change.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

#==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion htdocs/changecustompwdfield.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}

#==============================================================================
Expand Down
2 changes: 1 addition & 1 deletion htdocs/checkentropy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion htdocs/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion htdocs/resetbyquestions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion htdocs/resetbytoken.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 0 additions & 35 deletions lib/functions.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 )));
}
}

0 comments on commit a85b45e

Please sign in to comment.