Laravel - Change Password with Current Password Validation Example

By Ved Prakash N | Oct 09, 2022 | Laravel
Share :

How to Change Password with Current Password Validation Example

In this post, you will be learning how to change password with existing / current password validation in laravel.

Custom password change option in laravel.

Step 1: Install Laravel application and migrate and complete the basic setup of laravel.

Step 2: Create a route in routes/web.php file
Route::get('change-password', [App\Http\Controllers\ChangePasswordController::class, 'index']);
Route::post('change-password', [App\Http\Controllers\ChangePasswordController::class, 'changePassword']);

Step 3: Create a controller named ChangePasswordController as follows:
php artisan make:controller ChangePasswordController

Paste the below code in created ChangePasswordController.php
( app/Http/Controllers/ChangePasswordController.php )

namespace App\Http\Controllers\Frontend;

use App\Models\User;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ChangePasswordController extends Controller
    public function __construct()

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

    public function changePassword(Request $request)
            'current_password' => ['required','string','min:8'],
            'password' => ['required', 'string', 'min:8', 'confirmed']

        $currentPasswordStatus = Hash::check($request->current_password, auth()->user()->password);

                'password' => Hash::make($request->password),

            return redirect()->back()->with('message','Password Updated Successfully');


            return redirect()->back()->with('message','Current Password does not match with Old Password');

Step 4: Create a Blade file named change-password.blade.php in
( resources/views/change-password.blade.php ): 


<div class="py-5">
    <div class="container">
        <div class="row justify-content-center">
            <div class="col-md-6">

                @if (session('message'))
                    <h5 class="alert alert-success mb-2">{{ session('message') }}</h5>

                @if ($errors->any())
                <ul class="alert alert-danger">
                    @foreach ($errors->all() as $error)
                    <li class="text-danger">{{ $error }}</li>

                <div class="card shadow">
                    <div class="card-header bg-primary">
                        <h4 class="mb-0 text-white">Change Password</h4>
                    <div class="card-body">
                        <form action="{{ url('change-password') }}" method="POST">
                            <div class="mb-3">
                                <label>Current Password</label>
                                <input type="password" name="current_password" class="form-control" />
                            <div class="mb-3">
                                <label>New Password</label>
                                <input type="password" name="password" class="form-control" />
                            <div class="mb-3">
                                <label>Confirm Password</label>
                                <input type="password" name="password_confirmation" class="form-control" />
                            <div class="mb-3 text-end">
                                <button type="submit" class="btn btn-primary">Update Password</button>


Now you are ready to run this application for password change in laravel.

Thanks for reading.

Share this blog on social platforms