php - Why is Auth::attempt always returns false in Laravel 5.3? -


i'm new in laravel. try use multiple auth in laravel 5.3 , auth.php file is:

<?php  return [      */      'defaults' => [         'guard' => 'web',         'passwords' => 'users',     ],      'guards' => [         'web' => [             'driver' => 'session',             'provider' => 'users',         ],          'api' => [             'driver' => 'token',             'provider' => 'users',         ],          'courier' => [             'driver' => 'session',             'provider' => 'couriers',         ],          'client' => [             'driver' => 'session',             'provider' => 'clients',         ]     ],      'providers' => [         'couriers' => [             'driver' => 'eloquent',             'model' => app\courier::class,         ],          'clients' => [             'driver' => 'eloquent',             'model' => app\client::class,         ],          'users' => [             'driver' => 'eloquent',             'model' => app\user::class,         ]     ],      'passwords' => [         'couriers' => [             'provider' => 'couriers',             'table' => 'password_resets',             'expire' => 60,         ],          'clients' => [             'provider' => 'clients',             'table' => 'password_resets',             'expire' => 60,         ],     ],  ]; 

then, when store clients or couriers in db, use bcrypt password (bring use function hash::make() passwords). example, model courier is:

<?php  namespace app;  use illuminate\foundation\auth\user authenticatable;  class courier extends authenticatable {   [..]    public function setpasswordattribute($pass){         $this->attributes['password'] = bcrypt($pass);     }    [..] } 

and when update courier, in controller have:

public function update(request $request, $id) {          $fieldscourier = $request->all();         $courier = courier::find($id);          if( isset($fieldscourier['password']) )             $fieldscourier['password'] = bcrypt($fieldscourier['password']);          if( $courier->update($fieldscourier) )             $courier = courier::find($id);      } 

i have method called authenticate method attempt return false (invalid_credentials). send valid credentials.. code:

public function authenticate(request $request) {         $credentials = $request->only('email', 'password');          try {             if ( auth()->guard('courier')->attempt($credentials) ){                 $user = auth::guard('courier')->user();             } else {                 return response()->json(['error' => 'invalid_credentials'], 401);             }         } catch (jwtexception $e) {             return response()->json(['error' => 'could_not_create_token'], 500);         }          return response()->json(compact('user'));     } 

i not know i'm doing wrong. doing wrong?

you have encrypt password twice, on model , controller.

just remove 1 of them

e.g: don't use bcrypt on controller, because have use bcrypt on model.


Comments

Popular posts from this blog

sql server - Cannot query correctly (MSSQL - PHP - JSON) -

php - trouble displaying mysqli database results in correct order -

C++ Linked List -