What are the potential security risks associated with storing passwords in sessions, and how can they be mitigated using hashing techniques?

Storing passwords in sessions can expose them to potential security risks, such as session hijacking or unauthorized access. To mitigate these risks, passwords should be hashed before storing them in sessions. Hashing is a one-way encryption technique that converts passwords into a fixed-length string of characters, making it difficult for attackers to retrieve the original password.

// 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;