Is it a good practice to store user passwords, even in hashed form, in cookies in PHP?
Storing user passwords, even in hashed form, in cookies in PHP is not a good practice due to security risks. Cookies are stored on the user's browser and can potentially be accessed by malicious actors. It is recommended to store a secure token or session ID in the cookie instead of the actual password.
// Set a secure token in the cookie instead of the password
$token = bin2hex(random_bytes(16)); // Generate a random token
setcookie('auth_token', $token, time() + 3600, '/', '', true, true); // Set the cookie with secure and httpOnly flags