问答项目---账号密码异步校验后进行PHP校验

在做登陆的时候,通过异步校验后还需要通过PHP来校验账号和密码的正确性。

PHP校验账号密码:

public function login(){
    if(!IS_POST){echo "页面不存在"; $this->redirect('index'); die();};       
    $username = I('post.username');
    $pwd = I('post.password','','md5');
    $code = I('post.code');
    $obj = new \Think\Verify();
    if(!$obj->check($code)){
        $this->error('验证码错误');
    };
    //验证账号和密码       
    $where = array(
        'account' => $username
    );        
    $result = M('admin')->where($where)->find();   
    if(!$result || $result['password'] != $pwd){
         $this->error('账号或密码错误');
    };
    if($user['lock']){
        $this->error('账号被锁定');
    };
    $data = array(
        'id' => $result['id'],
        'logintime' => time(),
        'loginIp' => get_client_ip()
    );
    M('admin')->save($data);
    // 存session
    session('uid',$result['id']);
    session('uid',$result['account']);
    session('logintime',date('y-m-d H:i',$result['logintime']));
    session('loginip',$result['loginip']);
    $this->redirect('/admin/index','',2,'页面正在跳转中...');
}

 

posted @ 2017-08-13 23:30  帅到要去报警  阅读(319)  评论(0编辑  收藏  举报