Ad
Change Password Keeps Redirecting To Same Page
I am having a hard time debugging this code. I am just new to laravel and i don't know why this code keeps redirecting to the same page even if I used the correct methods. I am using the default authentication of laravel. I don't know if I'm missing something. Here's the code. Thanks!
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Hash;
class ChangePasswordController extends Controller
{
public function index(){
return view('Auth.passwords.changepassword');
}
public function changepassword(Request $request){
$this->validate($request, [
'oldpassword' => 'required',
'password' => 'required|confirmed'
]);
$hashedPassword = Auth::user()->password;
if(Hash::check($request->oldpassword, $hashedPassword)) {
$user = User::find(Auth::id());
$user->password = Hash::make($request->password);
$user->save();
Auth::logout();
return redirect()->route('login')->with('successMsg', "Password successfully changed");
}else{
return redirect()->back()->with('errorMsg', "Old Password is invalid");
}
}
}
Ad
Answer
try this code
$this->validate($request, [
'current_password' => 'required',
'password' => 'required|min:6',
'password_confirmation' => 'required|same:password'
]);
$current_password = $request->current_password;
$user = auth()->user();
if (Hash::check($current_password, $user->password)) {
$user->fill([
'password' => Hash::make($request->password)
])->save();
return redirect()->back()->with('success', 'Password Updated');
} else{
return redirect()->back()->with('error', 'Sorry a problem occurred while Updating this Password.');
}
Ad
source: stackoverflow.com
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS - Conditionally Load a Different Page
- → Make a Laravel collection into angular array (octobercms)
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?
- → Validating fileupload(image Dimensions) in Backend Octobercms
- → OctoberCMS Fileupload completely destroys my backend
- → How do I call the value from another backed page form and use it on a component in OctoberCms
Ad