Viewed   446 times

In laravel for registration I'm using encrypt algorithm for password instead of inbuilt bcrypt function in Laravel because to get password and send it to mail when password is forgot.

But decrypt it is showing a error like

DecryptException The MAC is invalid in Encrypter.php (line 184)

This , when I run this code it is working on local but server itself it is not working below i have mentioned the code , can anyone please help

public function forgotpassword(Request $request)
{
  $email=$request->email;
  $selectemail = User::select('email','password','name')
     ->where('email',$email)
     ->first();     

  if($selectemail)                       
  {                                 
    $password=decrypt($selectemail->password);
    $data = array( 'email' => $selectemail->email,'password' => $password , 'name' => $selectemail->name);

    Mail::send('email.resetpassword',$data,function($message) use ($email)
    {
      $message->to([$email])->subject('Forgot Password Letgo');
    });
      echo "Mail has sent successfully";
  } else {
    echo "This email is not yet registered";
  }             
}   

 Answers

3

The problem is you generated a new APP_KEY, then if you try to decrypt the old encrypted data it will show the DecryptException: The MAC is invalid.

If you want to decrypt the old data you need to restore your old APP_KEY.

After realizing that, now, adding a new problem there, if you stored new data with another APP_KEY or another encryption method you have a problem on the data because they are mixed on the table.

In case you don't know when do you started with the new encrypt method or differentiate the new encrypted entries, the fastest solution would be reset all the passwords with the new encrypt method.

You can learn more about how Laravel encryption works on the official Laravel docs.

Wednesday, September 7, 2022
3

Make sure to get() the subpages as IlluminateSupportCollection and mapWithKeys() to reformat the results. Use toArray() to provide the format Nova assumes:

private function selectOptions(): array
{
    $subpages = DB::table('subpages')->get();
    return $subpages->mapWithKeys(function ($subpage) {
        return [$subpage->slug => $subpage->slug];
    })->toArray();
}

This is how the returned result should look like:

[
    'my-article-1' => 'my-article-1',
    'my-article-2' => 'my-article-2',
    'my-article-3' => 'my-article-3',
]
Thursday, September 1, 2022
 
talha_q
 
2

The problem is related to browser cache, not Laravel.

To handle browser cache you can use the following code in one of your start files or in a service provider:

App::after(function($request, $response)
{
    $response->headers->set('Cache-Control','nocache, no-store, max-age=0, must-revalidate');
    $response->headers->set('Pragma','no-cache');
    $response->headers->set('Expires','Fri, 01 Jan 1990 00:00:00 GMT');
});

Here we are just modifying each responses within Laravel using application events.


Some people said that this works for all web browser but not for IE. So for IE, you should add a bunch of meta tags to your layout:

<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="cache-control" content="must-revalidate" />
<meta http-equiv="expires"       content="0" />
<meta http-equiv="expires"       content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma"        content="no-cache" />
Sunday, August 7, 2022
 
bummi
 
3

Decode to array and array_combine with the new keys.
Then loop the 'agent' and replace the keys again with array_combine.

$arr = json_decode($json, true);
$mainkeys = ["url", "secret_token", "agent"];
$subkeys = ["id", "quantity"];

$arr = array_combine(array_slice($mainkeys,0,count($arr)), $arr);

if(isset($arr["agent"])){
    foreach($arr["agent"] as &$val){
        $val = array_combine($subkeys, $val);
    }
}
unset($val); 

https://3v4l.org/mKePQ

array(3) {
  ["url"]=>
  string(26) "https://www.gosdoddgle.com"
  ["secret_token"]=>
  string(25) "stringstrinngstringstring"
  ["agent"]=>
  array(2) {
    [0]=>
    array(2) {
      ["id"]=>
      string(6) "sdsds1"
      ["quantity"]=>
      string(6) "sdsds1"
    }
    [1]=>
    &array(2) {
      ["id"]=>
      string(6) "sdsds1"
      ["quantity"]=>
      string(6) "sdsds1"
    }
  }
}
Tuesday, August 23, 2022
5

You haven't defined the user relationship on Post properly. By default, if you don't explicitly add the related tables, Eloquent will infer the name of the foreign key field from the table name, and the primary key name.

In your case, the relationship table name is user and the primary key of that table you have defined as user_id. Because of this, it assumes the foreign key in your APPLICATIONS table to be user_user_id.

To address this, explicity name your foreign and other table ids in your relationship:

public function user()
{
    return $this->belongsTo('AppUser', 'user_id', 'user_id');
}

The second parameter in the above code will be your foreign key on the APPLICATIONS table (since you haven't explicitly said what is meant to be)

Saturday, September 3, 2022
 
badp
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :
 
Share