我在UserController@getProfilePassword
和UserController@postProfilePassword
中创建了密码路由、视图和方法
At the moment, if I fill out the new_password
field, it gets hashed and submitted to the database correctly, then I can login with the new password.
但我需要能够验证new_password
和new_password_confirm
,以确保它们相同,并验证用户的当前密码.
How can I do that?
EDIT: I added $this->validate
to the method, but now I keep getting the error The password confirmation confirmation does not match.
even though they do match as I am using a simple password. Also I think I need to check against the current password manually as validator
won't do it for me.
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();
}
And this is the view
<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>