1.在模板中输入当前登录账号的密码,2次确认后post方法提交到后端
<tr>
<th><i class="require-red">*</i>旧密码:</th>
<td><input class="common-text" name="oldPwd" type="password"></td>
</tr>
<tr>
<th><i class="require-red">*</i>新密码:</th>
<td><input class="common-text required" id="title" name="newPwd" type="password">
</td>
</tr>
<tr>
<th><i class="require-red">*</i>密码确认:</th>
<td><input class="common-text required" id="title" name="reNewPwd" type="password">
</td>
</tr>
2.后端接收进行密码验证:验证通过则入库更改密码跳转到首页,如果失败则提示失败信息并再次回到修改界面
//获取当前登录用户的信息
$adminInfo=cookie('adminInfo');
$uid=$adminInfo['user_id'];
if(IS_POST){
//获取当前post修改过来的信息
$data=I('post.');
//旧密码md5加密后与cookie中存储的用户密码信息比对
$oldPwd=I('post.oldPwd','','md5');
$newPwd=I('post.newPwd','','md5');
$reNewPwd=I('post.reNewPwd','','md5');
//首先判断用户输入的旧密码是否与当前用户的密码是否一致
if($oldPwd!==$adminInfo['pwd']){ $this->error('旧密码输入错误,请重新输入!','',1);
}
//判断新旧密码是否相同
if($newPwd==$oldPwd){
$this->error('新旧密码一致,您未做任何修改!','',1);
//两次修改的密码是否一致
}elseif($newPwd!==$reNewPwd){
$this->error('密码确认不一致,请重新输入!','',1);
}else{
//修改数据库pwd字段的值
$result=M('admin')->where("user_id='$uid'")->setField('pwd',$newPwd);
if($result){
//如果密码修改成功,首先删除之前用户的cookie登录信息
cookie('adminInfo',null);
cookie('isLogin',null);
$this->success('密码修改成功!',U('Index/index'));
}else{
$this->error("密码修改失败!",'',1);
}
}
}
原文链接:https://blog.csdn.net/living_ren/article/details/78975111
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~