Laravel - Crypt::decrypt 问题,代码语法错误
Laravel - problem with Crypt::decrypt, wrong syntax in code
我知道我的解决方案是错误的,但是有人可以帮助我正确的语法如何解密我的字符串并登录吗?
Laravel API resived 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
语法不正确的问题,参考下面的 link 做了最终的解决方案:
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');
}
参考link:
我知道我的解决方案是错误的,但是有人可以帮助我正确的语法如何解密我的字符串并登录吗?
Laravel API resived 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
语法不正确的问题,参考下面的 link 做了最终的解决方案:
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');
}
参考link: