Thinkphp修改密码的实现
程序员文章站
2022-05-11 09:14:40
...
密码修改是开发中很基础的一个功能
密码修改的HTML代码如下
<form method =“post”class =“form-horizontal”action =“”>
<input type =“hidden”name =“id”value =“{$ paper_teacher.id}”>
<div class =“form-group”>
<label for =“inputEmail3”class =“col-sm-2 control-label”>用户名</ label>
<div class =“col-sm-5”>
<input type =“username”class =“form-control”id =“username”name =“username”value =“{$ paper_teacher.name}”>
</ DIV>
</ DIV>
<div class =“form-group”>
<label for =“inputPassword3”class =“col-sm-2 control-label”>密码</ label>
<div class =“col-sm-5”>
<input type =“password”class =“form-control”id =“password”name =“password”>
</ DIV>
</ DIV>
<div class =“form-group”>
<div class =“col-sm-offset-2 col-sm-10”>
</ DIV>
</ DIV>
<div class =“form-group”>
<div class =“col-sm-offset-2 col-sm-5”>
<button type =“submit”class =“btn btn-primary”>
<i class =“fa fa-gear”> </ i>
确定</按钮>
</ DIV>
</ DIV>
</ FORM>
代码中标红的必须要有
图像是这样的
然后就是后台代码了
公共功能编辑(){
$ paper_teacher = d( 'paper_teacher');
如果(IS_POST){
$数据[ '用户名'] = I( '用户名');
$数据[ 'ID'] = I( '编号');
$ paper_teacher_s = $ paper_teacher->找到($数据[ 'ID']);
$密码= $ paper_teacher_s [ '密码'];
如果(I( '密码')){
$数据[ '密码'] = MD5(I( '密码'));
}其他{
$数据[ '密码'] = $密码;
}
如果($ paper_teacher->创建($数据)){
$保存= $ paper_teacher->保存();
如果($保存!== FALSE){
$这个 - >成功( '修改管理员成功!',U( '指数/指数'));
}其他{
$这个 - >错误( '修改管理员失败!');
}
}其他{
$这 - >错误($ paper_teacher-> getError());
}
返回;
}
$ paper_teachers = $ paper_teacher->找(我( '身份证'));
$这 - >分配( 'paper_teacher',$ paper_teachers);
$这 - >显示();
}
希望对大家有所帮助 下一篇: 详解PHP如何实现一致性哈希算法
推荐阅读