Is it advisable to store multiple passwords in an array and compare them with user input in PHP?

Storing multiple passwords in an array in PHP is not advisable as it can pose a security risk if the array is compromised. It is recommended to store passwords securely hashed in a database and compare the hashed user input with the stored hashed passwords.

// Example of securely hashing and verifying passwords in PHP

// Store hashed passwords in a database
$passwords = [
    'user1' => password_hash('password1', PASSWORD_DEFAULT),
    'user2' => password_hash('password2', PASSWORD_DEFAULT)
];

// User input
$username = 'user1';
$input_password = 'password1';

// Verify password
if (array_key_exists($username, $passwords) && password_verify($input_password, $passwords[$username])) {
    echo 'Password is correct';
} else {
    echo 'Password is incorrect';
}