design this code <?php
session_start();

// Check if the user is logged in
if (!isset($_SESSION['username'])) {
    header("Location: user_login.php");
    exit();
}

$username = $_SESSION['username'];

// Database connection (adjust with your actual database credentials)
$servername = "localhost";
$dbusername = "root";  // Database username
$dbpassword = "";  // Database password
$dbname = "memos";  // Your database name

$conn = new mysqli($servername, $dbusername, $dbpassword, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // Sanitize inputs
    $current_password = mysqli_real_escape_string($conn, $_POST['current_password']);
    $new_password = mysqli_real_escape_string($conn, $_POST['new_password']);
    $confirm_password = mysqli_real_escape_string($conn, $_POST['confirm_password']);

    // Hashing the new password
    $hashed_new_password = password_hash($new_password, PASSWORD_DEFAULT);

    // Retrieve the stored password from the database
    $sql = "SELECT password FROM login WHERE username = '$username'";
    $result = $conn->query($sql);
    if ($result->num_rows > 0) {
        $row = $result->fetch_assoc();
        $stored_password = $row['password'];

        // Check if current password matches the stored password
        if (password_verify($current_password, $stored_password)) {
            // Check if the new password matches the confirm password
            if ($new_password === $confirm_password) {
                // Update the password
                $update_sql = "UPDATE login SET password = '$hashed_new_password' WHERE username = '$username'";
                if ($conn->query($update_sql) === TRUE) {
                    echo "<div class='alert alert-success'>Password updated successfully!</div>";
                } else {
                    echo "<div class='alert alert-danger'>Error updating password: " . $conn->error . "</div>";
                }
            } else {
                echo "<div class='alert alert-danger'>New password and confirm password do not match.</div>";
            }
        } else {
            echo "<div class='alert alert-danger'>Current password is incorrect.</div>";
        }
    } else {
        echo "<div class='alert alert-danger'>No user found with this username.</div>";
    }
}
$conn->close();
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Change Password</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
    <div class="container mt-5">
        <h2>Change Password</h2>
        <form method="POST" action="changes.php">
            <div class="mb-3">
                <label for="current_password" class="form-label">Current Password</label>
                <input type="password" class="form-control" id="current_password" name="current_password" required>
            </div>
            <div class="mb-3">
                <label for="new_password" class="form-label">New Password</label>
                <input type="password" class="form-control" id="new_password" name="new_password" required>
            </div>
            <div class="mb-3">
                <label for="confirm_password" class="form-label">Confirm New Password</label>
                <input type="password" class="form-control" id="confirm_password" name="confirm_password" required>
            </div>
            <button type="submit" class="btn btn-primary">Update Password</button>
        </form>
    </div>
</body>
</html>