用户登录时,流明密码哈希检查不起作用?

时间:2019-07-10 19:44:44

标签: lumen

/ *注册用户* /

公共功能寄存器(请求$ request){

    $user = User::create([
        'username' => $request->input('username'),
        'email' => $request->input('email'),
        'api_token' => Str::random(50),
        'password' => app('hash')->make($request->input('name'))
    ]);

    return response()->json(['user' => $user], 200);
}

/ *用户登录* /

公共功能登录(请求$ request){

    $user = User::where('email', $request->input('email'))
        ->first();

    if(!$user){
        return response()->json(['status' => 'error', 'message' => 'User not found!'], 401);
    }

    if(Hash::check($request->input('password'), $user->password)){

        $user->update(['api_token' => Str::random(50)]);

        return response()->json(['status' => 'success', 'message' => 'Logged in Successfully.'], 200);
    }

    return response()->json(['status' => 'error', 'message' => 'Credential Invalid!'], 401);
}

0 个答案:

没有答案