Is it recommended to store a single password directly in the PHP code for access control?

Storing a single password directly in the PHP code for access control is not recommended as it poses a security risk. If the code is compromised, the password can be easily accessed by attackers. Instead, it is recommended to store passwords securely hashed in a database and compare the hashed input with the stored hash for authentication.

// Store password securely hashed in the database
$storedPassword = password_hash("password123", PASSWORD_DEFAULT);

// Check if input password matches stored hash for authentication
$inputPassword = "password123";
if (password_verify($inputPassword, $storedPassword)) {
    // Password is correct
    echo "Access granted";
} else {
    // Password is incorrect
    echo "Access denied";
}