Laravel: Change Password with Current Password Validation
This guide demonstrates how to create a secure password change feature in Laravel, requiring users to confirm their current password before setting a new one.
Step 1: Install Laravel
Create a new Laravel project using Composer:
Step 2: Create a Custom Validation Rule
Generate a rule class to validate the old password:
Edit the generated file at app/Rules/MatchOldPassword.php
:
Step 3: Define Routes
Open routes/web.php
and add the following routes:
Step 4: Create the Controller
Generate and update app/Http/Controllers/ChangePasswordController.php
:
Step 5: Create Blade View
Create a Blade file at resources/views/changePassword.blade.php
:
Final Step: Run the Laravel Development Server
Visit your application in the browser:
🔗 http://localhost:8000/change-password