$error";
break;
}
// Check user password history
if (!secpass_check_history($user_id, $password)) {
$bad_password = true;
$errorMessage = "';
break;
}
// Password and Confirmed password checks
if ($password !== $password_confirm) {
$bad_password = true;
$errorMessage = "';
break;
}
// Compare current password with stored password
if ((!empty($user['password']) || !empty($current_password)) && !compat_password_verify($current_password, $user['password'])) {
$bad_password = true;
$errorMessage = "';
break;
}
// Check new password does not match stored password
if (compat_password_verify($password, $user['password'])) {
$bad_password = true;
$errorMessage = "';
break;
}
// If password isn't blank, password change is good to go
if ($password != '') {
if (read_config_option('secpass_expirepass') > 0) {
db_execute_prepared("UPDATE user_auth
SET lastchange = ?
WHERE id = ?
AND realm = 0
AND enabled = 'on'",
[time(), $user_id]);
}
$history = intval(read_config_option('secpass_history'));
if ($history > 0) {
$h = db_fetch_row_prepared("SELECT password, password_history
FROM user_auth
WHERE id = ?
AND realm = 0
AND enabled = 'on'",
[$user_id]);
$op = $h['password'];
$h = explode('|', $h['password_history']);
while (cacti_count($h) > $history - 1) {
array_shift($h);
}
$h[] = $op;
$h = implode('|', $h);
db_execute_prepared("UPDATE user_auth
SET password_history = ?
WHERE id = ?
AND realm = 0
AND enabled = 'on'",
[$h, $user_id]);
}
db_execute_prepared('INSERT IGNORE INTO user_log
(username, result, time, ip)
VALUES (?, 3, NOW(), ?)',
[$user['username'], get_client_addr()]);
db_check_password_length();
db_execute_prepared("UPDATE user_auth
SET must_change_password = '', password = ?
WHERE id = ?",
[compat_password_hash($password,PASSWORD_DEFAULT), $user_id]);
// Clear the auth cache for the user
db_execute_prepared('DELETE FROM user_auth_cache
WHERE user_id = ?',
[$_SESSION[SESS_USER_ID]]);
// Delete any user login sessions if using database sessions
db_execute_prepared('DELETE FROM sessions
WHERE user_id = ?',
[$_SESSION[SESS_USER_ID]]);
kill_session_var(SESS_CHANGE_PASSWORD);
kill_session_var(SESS_USER_ID);
raise_message('password_success');
header('Location: logout.php');
exit;
} else {
$bad_password = true;
}
break;
}
if (api_plugin_hook_function('custom_password', OPER_MODE_NATIVE) == OPER_MODE_RESKIN) {
exit;
}
if (grv('action') == 'force') {
$errorMessage = "*** " . __('Forced password change') . ' ***';
}
// Create tooltip for password complexity
$secpass_tooltip = "" . __('Password requirements include:') . '
';
$secpass_body = '';
if (read_config_option('secpass_minlen') > 0) {
$secpass_body .= __('Must be at least %d characters in length', read_config_option('secpass_minlen'));
}
if (read_config_option('secpass_reqmixcase') == 'on') {
$secpass_body .= ($secpass_body != '' ? '
' : '') . __('Must include mixed case');
}
if (read_config_option('secpass_reqnum') == 'on') {
$secpass_body .= ($secpass_body != '' ? '
' : '') . __('Must include at least 1 number');
}
if (read_config_option('secpass_reqspec') == 'on') {
$secpass_body .= ($secpass_body != '' ? '
' : '') . __('Must include at least 1 special character');
}
if (read_config_option('secpass_history') != '0') {
$secpass_body .= ($secpass_body != '' ? '
' : '') . __('Cannot be reused for %d password changes', read_config_option('secpass_history') + 1);
}
$secpass_tooltip .= $secpass_body;
$selectedTheme = get_selected_theme();
$skip_current = (empty($user['password']));
if (isrv('ref')) {
$ref_parts = parse_url(gnrv('ref'));
$valid = false;
// It's an array, so valid URL
if (is_array($ref_parts)) {
$valid = true;
}
// Someone trying to login via a get is bad!
if (isset($ref_parts['user']) || isset($ref_parts['pass'])) {
$valid = false;
}
// Someone trying to send an invalid host
if (!isset($ref_parts['host'])) {
$valid = false;
}
if ($valid) {
$server_addr = $_SERVER['SERVER_ADDR'];
if (!filter_var($_SERVER['SERVER_NAME'], FILTER_VALIDATE_IP)) {
$server_info = dns_get_record($_SERVER['SERVER_NAME'], DNS_ANY);
$server_ref = gethostbyname($ref_parts['host']);
if ($server_ref != $server_addr) {
$valid = false;
}
if (!$valid && cacti_sizeof($server_info)) {
foreach (($server_info ?: []) as $record) {
if (isset($record['host']) && $record['host'] == $server_ref) {
$valid = true;
break;
}
if (isset($record['target']) && $record['target'] == $server_ref) {
$valid = true;
break;
}
if (isset($record['ip']) && $record['ip'] == $server_addr) {
$valid = true;
break;
}
}
}
} else {
$server_ip = gethostbyname($_SERVER['SERVER_NAME']);
$server_ref = gethostbyname($ref_parts['host']);
if ($server_ip == $server_ref) {
$valid = true;
}
}
} else {
$valid = false;
}
if (!$valid) {
cacti_log('WARNING: User attempted to access Cacti from unknown URL', false, 'AUTH');
raise_message('problems_with_page', __('There are problems with the Change Password page. Contact your Cacti administrator right away.'), MESSAGE_LEVEL_ERROR);
header('Location:index.php');
exit;
}
}
if ($skip_current) {
$title_message = __('Please enter your current password and your new
Cacti password.');
} else {
$title_message = __('Please enter your new Cacti password.');
}
html_auth_header('change_password', __('Change Password'), __('Change Password'), $title_message);
?>