Login.php(validate)
<?php
namespace app\common\validate;
use think\Validate;
class Login extends Validate
{
protected $rule = [
'username' => 'require|max:20',
'password' => 'require|max:20',
];
}
app.php
<?php
return [
'password_pre_halt' => '_#sing_ty',//密码加密言
];
IAuth.php
<?php
namespace app\common\lib;
class IAuth
{
public static function setPassword($data)
{
return md5($data . config('app.password_pre_halt'));
}
}
修改Admin.php(controller)
$data['password'] = IAuth:: setPassword($data['password']);
Login.php(controller)
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2017/10/31
* Time: 15:37
*/
namespace app\admin\controller;
use app\common\lib\IAuth;
use think\Controller;
class Login extends Controller
{
public function index()
{
return $this->fetch();
}
/**
* 登陆相关业务
*/
public function check()
{
if (request()->isPost()) {
$data = input('post.');
if (!captcha_check($data['code'])) {
$this->error('验证码不正确');
}
//判定username password
$validate = validate('Login');
if (!$validate->check($data)) {
$this->error($validate->getError());
}
$user = model('AdminUser')->get(['username' => $data['username']]);
if (!$user || $user->status != 1) {
$this->error('该用户不存在');
}
if (IAuth:: setPassword($data['password']) != $user['password']) {
$this->error("密码不正确");
}
} else {
$this->error("请求不合法");
}
}
}