Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i decode hash value in laravel 5?

I have to convert my hash password into string.

here is my code.

<?php namespace App\Http\Controllers;
     use DB;
     use Auth;
     use Input;
     use Session;
     use Route;
     use Crypt;
     use Redirect;
     use Illuminate\Http\Request;
     use Illuminate\Http\Dispatcher; 

      $userdata = array(
                'email'     => $email,
                'password'  =>  Crypt::decrypt($password)
            );

when i use Crypt::decrypt i get error . error-

DecryptException in BaseEncrypter.php line 45:
The payload is invalid.

Can any one suggest me how can i do that?

Thanks.

like image 542
aniruddh Avatar asked Oct 05 '15 06:10

aniruddh


People also ask

Can you decrypt hash password in laravel?

@ershakti Passwords are hashed, not encrypted. That means they can't be reversed into their plain text form. This is for security reasons.

Can I decrypt hash?

Hash functions are created to not be decrypted, their algorithms are public. The only way to decrypt a hash is to know the input data.

How does laravel match hashed password?

From Laravel 5 onward, you can use the bcrypt() function to hash a plaintext. So, you can save that hashed password in DB and then, compare the hashed password again to match. $save_password = bcrypt('plain_text_password'); $check_password = bcrypt('provided_password_while_login_request'); And then, compare these two.


1 Answers

Use Crypt::decrypt()

$value = Crypt::decrypt($encrypted);

Note : You must decrypt the value with the same key used to encrypt it.

Laravel's encryption routines use Config::get('app.key') for encryption. This happens internally. Since this value is different for every Laravel application then the application that encrypts a value must also decrypt the value.

Or ...

The application must call Crypt::setKey() prior to decrypting to match the key to the value used for encrypting. See Setting the Encryption Key.

To Encryption use

Crypt::setKey($key);

This key will be used for subsequent Crypt::encrypt() and Crypt::decrypt() calls.

like image 71
Abdulla Nilam Avatar answered Sep 23 '22 01:09

Abdulla Nilam