What are the potential pitfalls of using session variables for storing sensitive information like passwords in PHP?

Storing sensitive information like passwords in session variables in PHP can be risky as session data is stored on the server and can be accessed by other scripts. To securely store sensitive information, it's recommended to use PHP's built-in session encryption functionality or store the information in a secure database.

// Use PHP's built-in session encryption functionality to securely store sensitive information
session_start();
$_SESSION['encrypted_password'] = password_hash($password, PASSWORD_DEFAULT);