Laravel-DecryptException:'MAC无效' [英] Laravel - DecryptException: 'The MAC is invalid'

查看:1224
本文介绍了Laravel-DecryptException:'MAC无效'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在laravel中进行注册时,我使用的是加密算法来加密密码,而不是在Laravel中使用内置的bcrypt函数,因为要获取密码并在忘记密码时将其发送给邮件.

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.

但是解密它会显示类似

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";
  }             
}   

推荐答案

问题是您生成了一个新的APP_KEY,然后,如果尝试解密旧的加密数据,它将显示DecryptException: The MAC is invalid.

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.

如果要解密旧数据,则需要还原旧的APP_KEY.

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

意识到这一点之后,现在,在其中添加一个新问题,如果您使用其他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.

您可以在官方 Laravel文档上了解有关Laravel加密工作原理的更多信息.

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

这篇关于Laravel-DecryptException:'MAC无效'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆