CREATE TABLE `admin` (
`id` int(11) NOT NULL,
`admin_name` varchar(255) NOT NULL,
`admin_password` varchar(255) NOT NULL,
`admin_mail` varchar(255) NOT NULL
)INSERT INTO `admin` (`id`, `admin_name`, `admin_password`, `admin_mail`) VALUES
(1, 'admin', '21232f297a57a5a743894a0e4a801fc3', 'admin@ideait.net');新增了修改密码功能,等验证码一起做好再发布上来,先把修改密码的代码贴出来:<?php
namespace app\common\model;
use think\Input;
class Admin extends \think\Model
{
public static function login($name, $password)
{
$where['admin_name'] = $name;
$where['admin_password'] = md5($password);
$user=Admin::where($where)->find();
if ($user) {
unset($user["password"]);
session("ext_user", $user);
return true;
}else{
return false;
}
}
// 退出登录
public static function logout(){
session("ext_user", NULL);
return [
"code" => 0,
"desc" => "退出成功"
];
}
// 查询一条数据
public static function search($name){
$where['admin_name'] = $name;
$user=Admin::where($where)->find();
return $user;
// dump($user['admin_password']);
}
//更改用户密码
public static function updatepassword($name,$newpassword){
$where['admin_name'] = $name;
$user=Admin::where($where)->update(['admin_password' => md5($newpassword)]);
if ($user) {
return true;
}else{
return false;
}
}
}
下面是在view/admin下面新增的一个changepsw.html文件的代码<!DOCTYPE html>
<html>
<head>
<title>修改密码</title>
</head>
<body>
<form method="post" action="changepassword">
原密码:<input type="password" name="oldpassword"></input>
新密码:<input type="password" name="newpassword"></input>
再次输入新密码:<input type="password" name="newpassword1"></input>
<input type="submit" value="提交"></input>
</form>
</body>
</html>下面是app/index/controller/Admin.php的代码<?php
namespace app\index\controller;
use \think\View;
use think\Controller;
class Admin extends Controller
{
public function index()
{
if (!session('?ext_user')) {
header(strtolower("location: ".config("web_root")."/index/login/login"));
exit();
}
$view = new View();
return $view->fetch('index');
}
// 退出登录
public function logout(){
\app\common\model\Admin::logout();
if (!session('?ext_user')) {
header(strtolower("location: ".config("web_root")."/index/login/login"));
exit();
}
header(strtolower("location:login"));
return NULL;
}
//修改密码
public function changepsw(){
if (!session('?ext_user')) {
header(strtolower("location: ".config("web_root")."/index/login/login"));
exit();
}
$view = new View();
return $view->fetch('changepsw');
}
public function changepassword(){
$oldpassword = md5(input('request.oldpassword'));
$newpassword = input('request.newpassword');
$newpassword1 = input('request.newpassword1');
$name=session('ext_user')['admin_name'];
$changepsw=\app\common\model\Admin::search($name);
// dump($changepsw['admin_password']);
$password=$changepsw['admin_password'];
if ($password==$oldpassword ) {
if ($newpassword==$newpassword1) {
$updatepassword=\app\common\model\Admin::updatepassword($name,$newpassword);
if ($updatepassword) {
session("ext_user", NULL);
return $this->success('修改成功,请重新登录', ''.config("web_root").'/index/login/login');
}else{
return $this->error("修改密码失败");
}
}else{
return $this->error("两次输入密码不一致");
}
}else{
return $this->error("原密码输入错误");
}
}
}[code][/code] 附件 login-demo.rar ( 545.34 KB 下载:1644 次 )
ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。