Hello Laravel Friends,

In today’s blog, we will learn about How to Change Password with Current Password in Laravel 8.

Security is the main concern for websites. Passwords protect our data but they must be frequently changed to avoid any data breach. Laravel provides default Change Password functionality.

Let’s check How to Change Password with Current Password in Laravel 8.

Prerequisites

Before we start, we need some prerequisites that are followed here.

  1. A Laravel Project.
  2. You have a basic idea of the login or authentication flow of Laravel

Perform Laravel Authentication with Breeze

Steps to Change Password with Current Password in Laravel 8:

Step 1: First you need to create a View File named change-password.blade.php at the below path

resources/views/user/change-password.blade.php

Then add the code as follows

Step 2: Now create UserController at the below path

app/Http/Controller/UserController.php

Also create supporting controller method

  1. changePassword function used for load view page
  2. changePasswordSave function is used for saving the new password and performing their validation.

Add the code as follows

Step 3: Add the below code to your route file

Now let’s test the result

Open {{YOUR HOST}}/change-password URL in your browser.

This will open a change password screen as follows

change password screen

If the new password is less than 8 characters, it will show the following error

new password invalid

If the current password is incorrect, it will show the following error

If the new password and confirm password do not match, it will show the following error

confirm password incorrect

If everything is entered correctly, the password gets successfully changed

password changed successfully

Conclusion:

This way you can Change Password with Current Password in Laravel 8. If you have any doubt let me know through the comments box. Share the tutorial with your friends and stay in touch with us for more Laravel tutorials.

Happy Coding!

Click to rate this post!
[Total: 2 Average: 5]