Faisal Shani
Faisal Shani

Reputation: 820

How to encrypt/decrypt a session value in Laravel

In my login controller I am creating a session with the value of email that user used to log in. From there I am using that session in different pages including home,profile and other pages. The issue is I dont want to store the raw email in session so anyone can read this using burpsuite or other tools, so I am decrypting the value of email before storing it in session. Now I dont know how can I get back the decrypted value on other pages. Below is the code.

//LoginController

 $email=encrypt($request->emailOrNumber);
 \Session::put('email',$email);

Now If I am trying to get this value using the below code in my blade view I am getting the encrypted value. How Can I get back the decrypted value of email? Need your suggestions. Thanks

{{Session::get('email')}}

Upvotes: 2

Views: 5210

Answers (1)

Clément Baconnier
Clément Baconnier

Reputation: 6108

As I said in the comment

To decrypt the email use decrypt() to decrypt the value returned by the session.

https://laravel.com/docs/master/encryption

decrypt(Session::get('email')); 

Upvotes: 2

Related Questions