I need to read a cookie in JS set by my Laravel app. Is there a way to do this in Laravel (as opposed to setting it directly through PHP) without overriding classes?
Since all Laravel cookies are encrypted and signed, cookie values are typically considered safe from client tampering.
Decrypt the cookie and check the digest: Decrypt de key of the cookie: do Base64 decoding, then decrypt it using your institution's private RSA key. Decrypt the data using the decrypted AES key. Check the digest using secutix public certificate. The following example in java will show you how to proceed.
2 ways: 1. $hashedPassword = User::find(1)->password; if (Hash::check('plain-text-password', $hashedPassword)) { // The passwords match... } $hashedPassword = User::find(1)->password; if (Hash::make('plain-text-password') === $hashedPassword) { // The passwords match... }
See the EncryptCookies
Middleware - this allows you to set the exceptions; that is, cookies that are not to be encrypted.
namespace App\Http\Middleware;
use Illuminate\Cookie\Middleware\EncryptCookies as BaseEncrypter;
class EncryptCookies extends BaseEncrypter
{
/**
* The names of the cookies that should not be encrypted.
*
* @var array
*/
protected $except = [
'my_cookie'
];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With