修改密码失败



大家好,我已经写了一个控制器函数,接受一个表单输入包含3个字段,oldpassword newpassword和confirmpassword字段。它应该根据系统中的内容检查旧密码并将其替换为newpassword。请求的dd显示我的控制器函数接收到请求,但无法保存新密码。请问我做错了什么?

这是我的控制器函数

public function update_password (Request $request)
{
// dd($request);
$request->validate([
'oldpassword' => ['required','string','min:8'],
'newpassword' => ['required', 'string', 'min:8', 'confirmed']
]);
$currentPasswordStatus = Hash::check($request->oldpassword, auth()->user()->password);
if($currentPasswordStatus){
User::findOrFail(Auth::user()->id)->update([
'password' => Hash::make($request->newpassword),
]);
dd($request->password);
return redirect()->route('profile')->with('message','Password Updated Successfully');
}else{
return redirect()->back()->with('message','Current Password does not match with Old Password');
}
}

这些是我的路线

Route::post('update_password', [AppHttpControllersAuthRegisteredUserController::class, 'update_password'])->name('change_password');
Route::get('update_password',[AppHttpControllersAuthRegisteredUserController::class, 'edit_password'])->name('edit_password');

这是我的输入表单

<div class="row g-7">
<form class="box" style="top: 50rem" method="POST"
action="{{ route('change_password') }}">
@csrf
<div>
<label class="font-italic mb-1" style="padding: 1rem">Enter Old Password:
</label>
<span><input id="password" class="block mt-1 w-full" type="password"
name="oldpassword" required /></span>
</div>
<div>
<label class="font-italic mb-1" style="padding: 1rem">Enter New Password:
</label>
<span><input id="password" class="block mt-1 w-full" type="password"
name="newpassword" required /></span>
</div>
<div>
<label class="font-italic mb-1" style="padding: 1rem">Confirm New Password:
</label>
<span><input id="password" class="block mt-1 w-full" type="password"
name="confirm" required /></span>
</div>
<div class="button">
<button type="submit"
class="btn btn-danger text-uppercase mr-2 px-4">reset
</button>
</div>
</form>
</div>

您正在对$request->newpassword进行验证,但试图使用$request->password进行更新。

还要注意return redirect()->routte('profile')的错别字。路由中只有一个"t">

相关内容

  • 没有找到相关文章