我正在尝试在我的项目中创建一个重置选项。如果用户是第一次登录,它将重定向到重置页面。
这是视图部分
<div class="form-group{{ ($errors->has('cpassword')) ? 'has error' : '' }}">
<label for="cpassword">Current Password: </label>
<input id="cpassword" name="cpassword" type="text" class="form-control">
@if($errors->has('cpassword'))
{{ $errors->first('cpassword')}}
@endif
</div>
<div class="form-group{{ ($errors->has('password')) ? 'has error' : '' }}">
<label for="password">New Password: </label>
<input id="password" name="password" type="password" class="form-control">
@if($errors->has('password'))
{{ $errors->first('password')}}
@endif
</div>
<div class="form-group{{ ($errors->has('password2')) ? 'has error' : '' }}">
<label for="password2">Confirm Password: </label>
<input id="password2" name="password2" type="password" class="form-control">
@if($errors->has('password2'))
{{ $errors->first('password2')}}
@endif
</div>
{{ Form::token() }}
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-default">
</div>
在重置页面我们需要输入旧密码,新密码和确认密码..
控制器部分如下
公共函数 postReset(){
$validator =Validator::make(Input::all(), array(
'cpassword' => 'required',
'password' => 'required|min:8',
'password2' => 'required|min:8|same:password'
));
if ($validator->fails())
{
return Redirect::route('resetPassword')->withErrors($validator)->withInput();
}
else
{
if (Auth::attempt(array('username'=>Auth::user()->username, 'password'=>Hash::make(Input::get('cpassword'))))) {
return 'password is resetted';
}
}
}
但是如果我尝试验证当前密码和用户密码,它们的哈希码不匹配。有没有其他方法可以重置密码。我需要相同的视图部分。有人可以帮忙吗??