How can PHP be used to authenticate multiple users with different passwords?

To authenticate multiple users with different passwords in PHP, you can store the usernames and passwords in a database or an array. When a user tries to log in, you can query the database or check the array to verify the username and password combination. If the combination is correct, you can set a session variable to indicate that the user is authenticated.

// Sample code to authenticate multiple users with different passwords
$users = [
    'user1' => 'password1',
    'user2' => 'password2',
    'user3' => 'password3'
];

if(isset($_POST['username']) && isset($_POST['password'])){
    $username = $_POST['username'];
    $password = $_POST['password'];

    if(array_key_exists($username, $users) && $users[$username] == $password){
        // Authentication successful
        session_start();
        $_SESSION['authenticated'] = true;
        echo "Authentication successful. Welcome, $username!";
    } else {
        // Authentication failed
        echo "Authentication failed. Please check your username and password.";
    }
}