samedi 2 mai 2020

How I login with Hashed Password in laravel

I am trying to login and sending email and password from Database. when i pass email and password to login function i gives the 401 unauthorized error. Strange thing is when i send password as a string it works. See the code below

public function verification(Request $request)
     {
        $user = User::find($request->user_id);

        if(Carbon::now() > $user->codeCreatedAt  && $user->verification_code !== $request->code) {
            return response()->json(['success' => false]);
        }
        $user->verify = 1;
        $user->save();
        $request->request->add([
            'email' => $user->email,
            'password' => $user->password

        ]);
        return $this->login($request);
    }

public function login(Request $request)
    {

        $credentials = $request->only('email', 'password');

        if ($token = $this->guard()->attempt($credentials)) {

            return $this->respondWithToken($token);
        }
        return response()->json(['errors' => 'Unauthorized'], 401);
    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire