How To Encrypt And Decrypt String In Laravel 8

Websolutionstuff | May-07-2021 | Categories : Laravel

In this example we will see how to encrypt and decrypt string in laravel 8 using crypt helper, As we all know laravel framework provide more security to user and that's why laravel provide encrypt of password or string to user, here we will see how to encrypt or decrypt string in laravel.

You need to use Crypt class to start encryptString and decryptString or some data.

 

use Crypt;
use App\Model\User;

 

Example 1 :

 

$user = new User();
$user->password = Crypt::encrypt($data['password']);
$user->save();

  public function encrypt()
   {
        $encrypted = Crypt::encryptString('websolutionstuff');
        print_r($encrypted);
   }
   
    public function decrypt()
    {
         $decrypt= Crypt::decryptString('your_encrypted_string');
         print_r($decrypt);
    }

 

Example 2 : 

 

$data = Request::all();

$user = new User();
$user->password = Crypt::encrypt($data['password']);
$user->save();

foreach ($user as $row)
{
  Crypt::decrypt($row->password);
}

 

Recommended Post
Featured Post
How to Reset MySQL Root User Password on Ubuntu
How to Reset MySQL Root User P...

Hey there! If you've ever found yourself scratching your head over a forgotten MySQL root password on Ubuntu, fear n...

Read More

Jan-26-2024

How To Convert PHP Array To JSON Object
How To Convert PHP Array To JS...

In this article, we will explore the process of converting a PHP array into a JSON object. We'll achieve this transf...

Read More

Jul-08-2020

How To Disable Future Date In jQuery Datepicker
How To Disable Future Date In...

In this tutorial, we will see how to disable future dates in jquery datepicker. In the date picker, today's dat...

Read More

Jun-17-2022

How To Get Current Date And Time In Node.js
How To Get Current Date And Ti...

In this example we will see how to get current date and time in Node.js application. In Node.js date and time are handle...

Read More

Sep-01-2021