How To Change Password In Laravel 9

Laravel | VueJs | PHP | Shopify | ReactJs | MySql
Search for a command to run...

Laravel | VueJs | PHP | Shopify | ReactJs | MySql
No comments yet. Be the first to comment.
Eloquent Factory & DB Seeder

Log in without a password by using the magic link in Laravel.

Verify Registered Mobile Number

Login with username / Mobile No / UUID

Upload image & Store in Public, Store or AWS S3.

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.
Route::get('/change-password', [App\Http\Controllers\HomeController::class, 'changePassword'])->name('change-password');
changePassword function in HomeControllerpublic function changePassword()
{
return view('change-password');
}
change-password.blade.php view file in resources/views@extends('layouts.app')
@section('content')
<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">
@csrf
<div class="card-body">
@if (session('status'))
<div class="alert alert-success" role="alert">
{{ session('status') }}
</div>
@elseif (session('error'))
<div class="alert alert-danger" role="alert">
{{ session('error') }}
</div>
@endif
<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">
@error('old_password')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
<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">
@error('new_password')
<span class="text-danger">{{ $message }}</span>
@enderror
</div>
<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>
</div>
<div class="card-footer">
<button class="btn btn-success">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
@endsection
The Output Will look like.

routes/web.php fileRoute::post('/change-password', [App\Http\Controllers\HomeController::class, 'updatePassword'])->name('update-password');
updatePassword function in app/Http/Controllers/HomeController.public function updatePassword(Request $request)
{
# Validation
$request->validate([
'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
User::whereId(auth()->user()->id)->update([
'password' => Hash::make($request->new_password)
]);
return back()->with("status", "Password changed successfully!");
}
the final output will look like.

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