In PHP, what are the security implications of storing passwords in plaintext in session variables temporarily?

Storing passwords in plaintext in session variables temporarily poses a significant security risk as it exposes sensitive information to potential attackers. To mitigate this risk, passwords should be securely hashed before storing them in session variables.

// Hash the password before storing it in the session
$password = 'password123';
$hashedPassword = password_hash($password, PASSWORD_DEFAULT);

// Store the hashed password in the session
$_SESSION['hashedPassword'] = $hashedPassword;