查看: 1240|回复: 0

微擎手机端开发掉用系统验证码

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2024-5-26 13:03:31 | 显示全部楼层 |阅读模式
//引入验证码类
  1. <?php
  2. defined('IN_IA') and defined('IN_MOBILE') or exit('Access Denied');
  3. global $_W, $_GPC;
  4. load()->model('user');
  5. load()->model('message');
  6. load()->classs('oauth2/oauth2client');
  7. load()->model('setting');

  8. $settings = $this->module['config'];
  9. /*if ($_SESSION['admin']){
  10. echo $_SESSION['admin'];
  11. }*/

  12.                
  13.         //message($_SESSION['admin']."欢迎回来,{$admin['name']}。", $this->createMobileUrl('login', array('p' => 'admin')));

  14. $cgc_kanjia_zhuli_shop = new common_model("cgc_kanjia_zhuli_shop");
  15. //        message('hkl'.$settings['version_desc']);
  16. /*if (!empty($_GPC['id']) && !empty($_GPC['code'])) {
  17.         $admin = $cgc_kanjia_zhuli_shop->getOne($_GPC['id']);      
  18.         if (empty($admin)) {
  19.                 message('请登录', $this->createMobileUrl('login', array('p' => 'admin')), 'SUCCESS');
  20.         }
  21.       
  22.         $code = md5($admin['loginname'] . $admin['password']);
  23.         if ($code == $_GPC['code']) {               
  24.                 $_SESSION['admin'] = $admin;
  25.                 message('', $this->createMobileUrl('goods', array('p' => 'admin', 'op' => 'info')), 'SUCCESS');
  26.                
  27.         } else {
  28.                 message('请登录', $this->createMobileUrl('login', array('p' => 'admin')), 'SUCCESS');
  29.         }
  30. }
  31. */
  32. if (checksubmit('login')) {
  33.         $loginname = trim($_GPC['loginname']);
  34.       
  35.         $verify = trim($_GPC['verify']);
  36.         if (empty($verify)) {
  37.                 message('请输入验证码', '', 'error');
  38.         }
  39.         $result = checkAdminCaptcha($verify, $this->modulename);
  40.         if (empty($result)) {
  41.                 message('验证码错误了,可重新换一张验证码图片在输入.', '', 'error');
  42.         }
  43.         if (empty($loginname)) {
  44.                 message('请输入要登录的用户名', '', 'error');
  45.         }
  46.         $password = $_GPC['password'];
  47.       
  48.         if (empty($password)) {
  49.                 message('请输入密码', '', 'error');
  50.         }
  51.         $con = " loginname = '{$loginname}'";

  52.         $admin = $cgc_kanjia_zhuli_shop->getByCon($con);
  53.       
  54.         if (empty($admin)) {
  55.                 message('登录失败,请检查您输入的用户名和密码1!');
  56.         }
  57.       
  58.         if (md5($password) == $admin['password']) {
  59.                 if ($admin['status'] != 1) {
  60.                         message('您的账号已被禁用!', '', 'error');
  61.                 }
  62.                
  63.                 if(!empty($admin['validity_date'])&&$admin['validity_date']<=time()){
  64.                         message('您的账号已过期!','','error');
  65.                 }
  66.                
  67.                 //$_SESSION['cgc_kanjia_zhuli_admin'] = $admin;
  68.                 $_SESSION['admin'] = $admin['id'];
  69.                
  70.                
  71.                
  72.                 if(!empty($settings['login_user'])&& !empty($settings['login_password']) && empty($_GPC['__session'])){
  73.                         $_GPC['username'] = $settings['login_user'];
  74.                         $_GPC['password'] = $settings['login_password'];         
  75.                         _login(array('username'=>$_GPC['username'],'password'=>$_GPC['password']),$this->createMobileUrl('goods', array('p' => 'admin')));
  76.                        
  77.                 }
  78.                
  79.                 header("location:".$this->createMobileUrl('goods', array('p' => 'admin')));               
  80.                 //message("欢迎回来,{$admin['name']}。", $this->createMobileUrl('login', array('p' => 'admin')));
  81.         } else {
  82.                 message('登录失败,请检查您输入的用户名和密码!', '', 'error');
  83.         }
  84.       
  85. }


  86.   if ($_GPC['userkey']){
  87.      getUserKey();
  88.   }
  89.   if ($settings['template_mode'] == 1) {
  90.         include $this->template("login1");
  91.         exit();
  92.   }
  93.   include $this->template("login1");
  94.   exit();

  95. if ($_GPC['op'] == 'loginout') {
  96.   unset($_SESSION['admin']);
  97.   unset($_SESSION['cgc_kanjia_zhuli_admin']);
  98.   //if $cookie['hash']
  99. /*  isetcookie('__session', '', -10000);
  100.   isetcookie('__switch', '', -10000);*/
  101.   
  102.   message('已退出登录', $this->createMobileUrl('login', array('p' => 'admin')), 'SUCCESS');
  103. }


  104. function checkAdminCaptcha($code, $modulename) {
  105.         global $_W, $_GPC;
  106.         session_start();
  107.         $codehash = md5(strtolower($code));
  108.         if (!empty($_GPC[$modulename . '_admin_code']) && $codehash == $_SESSION[$modulename . '_admin_code']) {
  109.                 $return = true;
  110.         } else {
  111.                
  112.                 $return = false;
  113.         }
  114.         $_SESSION[$modulename . '_admin_code'] = '';
  115.         isetcookie($modulename . '_admin_code', '');
  116.         return $return;
  117. }


  118. function _login($member,$forward = '') {
  119.         global $_GPC, $_W;
  120.         if (empty($_GPC['login_type'])) {
  121.                 $_GPC['login_type'] = 'system';
  122.         }
  123.       
  124.         if (empty($_GPC['handle_type'])) {
  125.                 $_GPC['handle_type'] = 'login';
  126.         }
  127.       
  128. /*        if ($_GPC['handle_type'] == 'login') {
  129.                 $zz=OAuth2Client::create($_GPC['login_type'], $_W['setting']['thirdlogin'][$_GPC['login_type']]['appid'], $_W['setting']['thirdlogin'][$_GPC['login_type']]['appsecret']);
  130.                 print_r(get_class($zz));
  131.         exit("dd");
  132.                 $member = OAuth2Client::create($_GPC['login_type'], $_W['setting']['thirdlogin'][$_GPC['login_type']]['appid'], $_W['setting']['thirdlogin'][$_GPC['login_type']]['appsecret'])->login();
  133.         } else {
  134.                
  135.                 //$member = OAuth2Client::create($_GPC['login_type'], $_W['setting']['thirdlogin'][$_GPC['login_type']]['appid'], $_W['setting']['thirdlogin'][$_GPC['login_type']]['appsecret'])->bind();
  136.         }*/


  137.         $record = user_single($member);
  138.         if (!empty($record)) {      
  139.                 $_W['uid'] = $record['uid'];
  140.                 $_W['user'] = $record;
  141.                 $cookie = array();
  142.                 $cookie['uid'] = $record['uid'];
  143.                 $cookie['lastvisit'] = $record['lastvisit'];
  144.                 $cookie['lastip'] = $record['lastip'];
  145.                 $cookie['hash'] = md5($record['password'] . $record['salt']);
  146.                 $session = authcode(json_encode($cookie), 'encode');
  147.                 isetcookie('__session', $session, !empty($_GPC['rember']) ? 7 * 86400 : 0, true);
  148.                 $status = array();
  149.                 /*$status['uid'] = $record['uid'];
  150.                 $status['lastvisit'] = TIMESTAMP;
  151.                 $status['lastip'] = CLIENT_IP;
  152.                 user_update($status);*/
  153.             //$_SESSION['user_destroy'] = $true;
  154.       

  155.                 message("欢迎回来。",$forward);
  156.         } else {
  157.       
  158.                 //message('登录失败,账号和密码', '', '');
  159.         }
  160. }
复制代码

自定义验证码验证函数
  1. function checkAdminCaptcha($code, $modulename) {
  2.         global $_W, $_GPC;
  3.         session_start();
  4.         $codehash = md5(strtolower($code));
  5.         if (!empty($_GPC[$modulename . '_admin_code']) && $codehash == $_SESSION[$modulename . '_admin_code']) {
  6.                 $return = true;
  7.         } else {
  8.                
  9.                 $return = false;
  10.         }
  11.         $_SESSION[$modulename . '_admin_code'] = '';
  12.         isetcookie($modulename . '_admin_code', '');
  13.         return $return;
  14. }
复制代码
引自百川砍价

道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部