Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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";
  }             
}   
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
1.3k views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...