where('id', $_SESSION['user_id']); $user = $db->getOne('users'); if ($user === NULL || !password_verify($current_password, $user['password'])) { $_SESSION['failure'] = 'Current password is incorrect.'; } elseif (strlen($new_password) < 10) { $_SESSION['failure'] = 'New password must be at least 10 characters long.'; } elseif ($new_password !== $confirm_password) { $_SESSION['failure'] = 'New password and confirmation do not match.'; } elseif ($new_password === $current_password) { $_SESSION['failure'] = 'New password must be different from the current password.'; } else { $db = getDbInstance(); $db->where('id', $_SESSION['user_id']); $db->update('users', [ 'password' => password_hash($new_password, PASSWORD_DEFAULT), 'must_change_password' => 0, 'password_changed_at' => date('Y-m-d H:i:s'), ]); $_SESSION['must_change_password'] = false; audit_log('password_changed'); $_SESSION['success'] = 'Password updated successfully.'; header('Location: index.php'); exit; } } ?>