【发布时间】:2016-06-01 00:52:55
【问题描述】:
我已经在UserController@getProfilePassword和UserController@postProfilePassword中创建了密码路由、视图和方法
目前,如果我填写new_password字段,它会被正确地哈希并提交到数据库,然后我可以使用新密码登录。
但我需要能够验证 new_password 和 new_password_confirm 以确保它们相同并验证用户的当前密码。
我该怎么做?
编辑:我在方法中添加了$this->validate,但现在我不断收到错误The password confirmation confirmation does not match.,即使它们确实匹配,因为我使用的是简单密码。另外我认为我需要手动检查当前密码,因为 validator 不会为我做。
public function getProfilePassword(Request $request) {
return view('profile/password', ['user' => Auth::user()]);
}
public function postProfilePassword(Request $request) {
$user = Auth::user();
$this->validate($request, [
'old_password' => 'required',
'password' => 'required|min:4',
'password_confirmation' => 'required|confirmed'
]);
$user->password = Hash::make(Input::get('new_password'));
$user->save();
}
这就是风景
<form action="{{ route('profile/updatepassword') }}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="name">Current Password</label>
<input type="password" name="old_password" class="form-control" id="old_password">
</div>
<div class="form-group">
<label for="name">Password</label>
<input type="password" name="password" class="form-control" id="password">
</div>
<div class="form-group">
<label for="name">New Password</label>
<input type="password" name="password_confirmation" class="form-control" id="password_confirmation">
</div>
<button type="submit" class="btn btn-primary">Change Password</button>
<input type="hidden" value="{{ Session::token() }}" name="_token">
</form>
【问题讨论】:
标签: php laravel laravel-5 laravel-5.2