How can the code be improved to handle the blockage of an account after 5 unsuccessful login attempts?

To handle the blockage of an account after 5 unsuccessful login attempts, we can introduce a counter that increments with each unsuccessful login attempt. Once the counter reaches 5, we can update a flag in the database to indicate that the account is blocked. Additionally, we can add a check in the login process to verify if the account is blocked before allowing further login attempts.

// Check if the account is blocked before allowing login
if($login_attempts >= 5) {
    // Update database to set account as blocked
    $query = "UPDATE users SET blocked = 1 WHERE username = '$username'";
    // Execute query
    // Display error message to user
} else {
    // Handle regular login process
}