How To Change Password In Laravel 9

How To Change Password In Laravel 9


2 min read

I am going to explain here, how you can change the password in laravel 9.

I have installed the laravel with Laravel Authentication and going to explain about changing the password of logged-in user.

Step 1 - Change Password Page:

Create a route for change password

Route::get('/change-password', [App\Http\Controllers\HomeController::class, 'changePassword'])->name('change-password');

Cerate changePassword function in HomeController

public function changePassword()
   return view('change-password');

Create change-password.blade.php view file in resources/views


    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-8">
                <div class="card">
                    <div class="card-header">{{ __('Chnage Password') }}</div>

                    <form action="{{ route('update-password') }}" method="POST">
                        <div class="card-body">
                            @if (session('status'))
                                <div class="alert alert-success" role="alert">
                                    {{ session('status') }}
                            @elseif (session('error'))
                                <div class="alert alert-danger" role="alert">
                                    {{ session('error') }}

                            <div class="mb-3">
                                <label for="oldPasswordInput" class="form-label">Old Password</label>
                                <input name="old_password" type="password" class="form-control @error('old_password') is-invalid @enderror" id="oldPasswordInput"
                                    placeholder="Old Password">
                                    <span class="text-danger">{{ $message }}</span>
                            <div class="mb-3">
                                <label for="newPasswordInput" class="form-label">New Password</label>
                                <input name="new_password" type="password" class="form-control @error('new_password') is-invalid @enderror" id="newPasswordInput"
                                    placeholder="New Password">
                                    <span class="text-danger">{{ $message }}</span>
                            <div class="mb-3">
                                <label for="confirmNewPasswordInput" class="form-label">Confirm New Password</label>
                                <input name="new_password_confirmation" type="password" class="form-control" id="confirmNewPasswordInput"
                                    placeholder="Confirm New Password">


                        <div class="card-footer">
                            <button class="btn btn-success">Submit</button>


The Output Will look like.

Change Password

Step 2 - Handle the Form Submit.

Create a POST route in routes/web.php file

Route::post('/change-password', [App\Http\Controllers\HomeController::class, 'updatePassword'])->name('update-password');

Create updatePassword function in app/Http/Controllers/HomeController.

public function updatePassword(Request $request)
        # Validation
            'old_password' => 'required',
            'new_password' => 'required|confirmed',

        #Match The Old Password
        if(!Hash::check($request->old_password, auth()->user()->password)){
            return back()->with("error", "Old Password Doesn't match!");

        #Update the new Password
            'password' => Hash::make($request->new_password)

        return back()->with("status", "Password changed successfully!");

the final output will look like.

Change Password

The Complete Video Tutorial is below in the video.

If you face any issues while implementing, please comment on your query.

Thank You for Reading

Reach Out To me. Twitter Instagram TechToolIndia YouTube Channel

Did you find this article valuable?

Support Shani Singh by becoming a sponsor. Any amount is appreciated!