Created
December 16, 2018 18:54
-
-
Save mahamudul310/2f9d7da1ee7e0be3d9bbf15c8ecf7b7d to your computer and use it in GitHub Desktop.
Password Updated in Laravel
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Route::put('profile-update','SettingsController@updateProfile')->name('profile.update'); | |
Route::put('password-update','SettingsController@updatePassword')->name('password.update'); | |
=================================== Controller ===================================== | |
use App\User; | |
use Brian2694\Toastr\Facades\Toastr; | |
use Carbon\Carbon; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Support\Facades\Hash; | |
use Illuminate\Support\Facades\Storage; | |
use Intervention\Image\Facades\Image; | |
public function updatePassword(Request $request) | |
{ | |
$this->validate($request, [ | |
'old_password' => 'required', | |
'password' => 'required|confirmed', | |
]); | |
$hashedPassword = Auth::user()->password; | |
if(Hash::check($request->old_password, $hashedPassword)) | |
{ | |
if(!Hash::check($request->password, $hashedPassword)) | |
{ | |
$user = User::find(Auth::id()); | |
$user->password = Hash::make($request->password); | |
$user->save(); | |
Toastr::success('Password Successfully Change','Success'); | |
Auth::logout(); | |
return redirect()->back(); | |
} else { | |
Toastr::error('New password cannot be the same as old password.','Error'); | |
return redirect()->back(); | |
} | |
} else { | |
Toastr::error('Current password not match','Error'); | |
return redirect()->back(); | |
} | |
} | |
=================================== Form ===================================== | |
<form method="POST" action="{{ route('author.password.update') }}" class="form-horizontal"> | |
@csrf | |
@method('PUT') | |
<div class="row clearfix"> | |
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label"> | |
<label for="old_password">Old Password :</label> | |
</div> | |
<div class="col-lg-10 col-md-10 col-sm-8 col-xs-7"> | |
<div class="form-group"> | |
<div class="form-line"> | |
<input type="password" name="old_password" id="old_password" class="form-control" placeholder="Enter your old password" > | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="row clearfix"> | |
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label"> | |
<label for="password">New Password :</label> | |
</div> | |
<div class="col-lg-10 col-md-10 col-sm-8 col-xs-7"> | |
<div class="form-group"> | |
<div class="form-line"> | |
<input type="password" name="password" id="password" class="form-control" placeholder="Enter your new password" > | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="row clearfix"> | |
<div class="col-lg-2 col-md-2 col-sm-4 col-xs-5 form-control-label"> | |
<label for="confirm_password">Confirm Password :</label> | |
</div> | |
<div class="col-lg-10 col-md-10 col-sm-8 col-xs-7"> | |
<div class="form-group"> | |
<div class="form-line"> | |
<input type="password" name="password_confirmation" id="confirm_password" class="form-control" placeholder="Enter your new pawword again" > | |
</div> | |
</div> | |
</div> | |
</div> | |
<div class="row clearfix"> | |
<div class="col-lg-offset-2 col-md-offset-2 col-sm-offset-4 col-xs-offset-5"> | |
<button type="submit" class="btn btn-primary m-t-15 waves-effect">UPDATE</button> | |
</div> | |
</div> | |
</form> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment