Home > Software design >  User Credentials do not match the records after user update profile
User Credentials do not match the records after user update profile

Time:07-20

Am having a problem trying user login after updating user profile, credentials are updated successfully and the logout process is successfull, but when i try logging in with the updated and previous credentials i get the error "this credentials do not match our records"...i dont know where i am getting then logic wrong, i will appreciate any answer THANKS.

below is my LoginController

      <?php
        
        namespace App\Http\Controllers\Auth;
        
        use App\Http\Controllers\Controller;
        use App\Providers\RouteServiceProvider;
        use Illuminate\Foundation\Auth\AuthenticatesUsers;
        
        class LoginController extends Controller
        {
            /*
            |--------------------------------------------------------------------------
            | Login Controller
            |--------------------------------------------------------------------------
            |
            | This controller handles authenticating users for the application and
            | redirecting them to your home screen. The controller uses a trait
            | to conveniently provide its functionality to your applications.
            |
            */
        
            use AuthenticatesUsers;
        
            /**
             * Where to redirect users after login.
             *
             * @var string
             */
            protected $redirectTo = RouteServiceProvider::HOME;
        
            /**
             * Create a new controller instance.
             *
             * @return void
             */
            public function __construct()
            {
                $this->middleware('guest')->except('logout');
            }
        }
    

And my UpdateProfileRequest

    <?php
    
    namespace App\Http\Requests\User;
    
    use Illuminate\Foundation\Http\FormRequest;
    
    class UpdateProfileRequest extends FormRequest
    {
        /**
         * Determine if the user is authorized to make this request.
         *
         * @return bool
         */
        public function authorize()
        {
            return true;
        }
    
        /**
         * Get the validation rules that apply to the request.
         *
         * @return array
         */
        public function rules()
        {
            return [
                'name'=>'required',
                'organization'=>'required',
                'email'=>'required',
                'password'=>'required'
                
            ];
        }
    }

Below is my UserController

<?php


namespace App\Http\Controllers;
use App\Http\Requests\User\UpdateProfileRequest;
use Illuminate\Http\Request;
use App\User;


class UserController extends Controller
{
    //
    public function edit()
    {
        return view('users.edit')->with('user', auth()->user());
    }

    public function update(UpdateProfileRequest $request)
    {
        $user = auth()->user();

        $user->update([
            'name' => $request->name,
            'organization' => $request->organization,
            'email' => $request->email,
            'password' => $request->password
        ]);

    
        return redirect()->back();
    }
}

I will appreciate any help

CodePudding user response:

laravel doesn't allow you to login if your password is not hashed so while updating you must hash your password like this

'password' => Hash::make($request->password);
  • Related