Laravel Change Password with Current Password Validation Example

Laravel updates a new password using the old password in laravel. These tutorials demonstrate to you, how you can easily update the new password with validation old password.

Here you will learn, how to validate input fields like old password, new password and confirm password using laravel validation rules.

Laravel change password old password validation

In this example, this below function accepts three parameters like old password, new password and confirm password. If you entered the wrong password this function returns back with your laravel route.

public function updatePassword(Request $request)
{
    $this->validate($request, [
        'old_password'     => 'required',
        'new_password'     => 'required|min:6',
        'confirm_password' => 'required|same:new_password',
    ]);

    $data = $request->all();

    $user = User::find(auth()->user()->id);

    if(!\Hash::check($data['old_password'], $user->password)){

         return back()->with('error','You have entered wrong password');

    }else{

       here you will write password update code

    }
}

Conclusion

Here, you have learned how you can change the password with your old password validation.

Recommended Laravel Tutorials

Recommended:-Laravel Try Catch

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *