[英]Laravel - problem with Crypt::decrypt, wrong syntax in code
我知道我的解决方案是错误的,但是有人可以用正确的语法帮助我如何解密我的字符串并登录吗?
Laravel API 恢复code
并在Database
加密存储
api route
Route::post('data','DataImport@Insert');
controller
use Illuminate\Support\Facades\Crypt;
function Insert(Request $request)
{
$user=new User();
$user->code=Crypt::encrypt($request->input('code'));
return $user->save();
}
Auth\\Controller
use Illuminate\Support\Facades\Crypt;
public function postLogin(Request $request)
{
request()->validate([
'id_message' => 'required',
'code' => 'required',
]);
$credentials = $request->only('id_message', 'code');
$decrypted = $request->input('code');
$request->session()->flash('success');
if ($user=User::where($credentials)->first()) {
if (\Crypt::decrypt($user->code) == $decrypted) {
Auth::login($user);
return redirect()->intended('dashboard')->with('success');
}
}
//dd($decrypted);
return Redirect::back()->with('error');
}
dd($decrypted);
array:1 [▼
"code" => "123456"
]
解密的code
是正确的值。 laravel.log
没有错误,只有消息代码不匹配。
谢谢你的帮助。
(散列解决方案,不要帮我解决这个问题)
如果有人有同样的问题。 @lagbox帮我配不正确的语法与input
的下方,参考链接做了最终的解决方案:
replace this:
$credentials = $request->only('id_message', 'sms_code');
to:
$user = User::where('id_message', $request->input('id_message'))->first();
if
声明为:
if ($user) {
if (\Crypt::decrypt($user->code) == $decrypted) {
Auth::login($user);
return redirect()->intended('dashboard')->with('success');
}
}
return Redirect::back()->with('error');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.