Exemple #1
0
/**
 * 截取字符窜
 *
 * @access      public
 * @param       string      $str            要截取的字符串
 * @param       string      $num            数量
 * @param       bool      $ellipsis         是否省略号
 * @return      string
 */
function hy_substr($str, $num, $ellipsis = false)
{
    $new_str = '';
    $str = trim($str);
    $suffix = '';
    if ($ellipsis) {
        $suffix = '...';
    }
    if (hy_strlen($str) <= $num) {
        $new_str = $str;
    } else {
        for ($i = 0; $i < $num; $i++) {
            if (ord(substr($str, $i, $i + 1)) > 127) {
                $new_str .= substr($str, $i, 3);
                $i = $i + 2;
                $num = $num + 2;
            } else {
                $new_str .= substr($str, $i, 1);
            }
        }
        $new_str = $new_str . $suffix;
    }
    return $new_str;
}
 /**
  * 修改密码
  */
 public function repwd()
 {
     if ($_POST) {
         $post = I('post.');
         //print_r($post);
         $is_exist = M('UserRelog')->where(array('userid' => $post['userid'], 'vcode' => $post['vcode']))->count();
         if ($is_exist == 0) {
             $this->error("标识vcode错误", "/");
         }
         if (empty($post['newpwd'])) {
             $this->error("请输入新密码");
         }
         if (empty($post['newpwd2'])) {
             $this->error("请输入确认密码");
         }
         if (hy_strlen($post['newpwd']) < 6) {
             $this->error("输入的密码不能小于6个字符");
         }
         if ($post['newpwd'] != $post['newpwd']) {
             $this->error("输入的两次密码不一致");
         }
         //$user = M('User')->where(array('userid' => $post['userid']))->field("authkey")->find();
         $res = D('User/User')->ChangePassword($post['uname'], $post['newpwd']);
         if ($res) {
             $this->success("修改成功", "/");
         } else {
             $this->error("修改失败");
         }
     } else {
         if ($this->userid) {
             $this->error("你已经登录了", "/");
         }
         $info = I('get.');
         $data = M('UserRelog')->where(array('userid' => $info['userid']))->find();
         $now_time = time() - 3 * 24 * 60 * 60;
         if ($data['create_time'] < $now_time) {
             $this->error("该链接已经失效", "/");
         }
         if ($data['vcode'] != $info['vcode']) {
             $this->error("标识vcode不正确", "/");
         }
         $uname = M('User')->where(array('userid' => $info['userid']))->getField("uname");
         $this->assign("uname", $uname);
         $this->assign("info", $info);
         $this->display();
     }
 }
 public function random()
 {
     if ($_POST) {
         $res = array('error' => 1, 'content' => '');
         $status = yf_empty(intval($_POST['status']), 0, true);
         if ($status == 0) {
             $clear = Model('other')->clear_db();
             if (!$clear) {
                 $res['content'] = "系统错误";
                 $this->showMsg($res);
             }
         }
         $str1 = "0123456789";
         $str2 = "abcdefghijklmnopqrstuvwxyz";
         $str3 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
         $type = yf_empty(intval($_POST['type']), 0, true);
         if ($type == 0) {
             $str = $str1 . $str2 . $str3;
         } elseif ($type == 1) {
             $str = $str1;
         } elseif ($type == 2) {
             $str = $str2;
         } elseif ($type == 3) {
             $str = $str3;
         } elseif ($type == 4) {
             $str = $str1 . $str2;
         } elseif ($type == 5) {
             $str = $str1 . str3;
         } elseif ($type == 6) {
             $str = $str2 . $str3;
         }
         $num = yf_empty(intval($_POST['num']), "请输入长度");
         $count = yf_empty(intval($_POST['count']), "请输入数量");
         $patterm = yf_empty($_POST['patterm'], "", true);
         $type_num = yf_empty($_POST['type_num'], '', true);
         $num_arr = array();
         if (!empty($type_num)) {
             $num_arr = explode(",", $type_num);
             if (count($num_arr) != 3) {
                 $res['content'] = "输入的字符数量格式不正确";
                 $this->showMsg($res);
             } else {
                 if ($num != $num_arr[0] + $num_arr[1] + $num_arr[2]) {
                     $res['content'] = "输入的字符数量加起来的和不正确";
                     $this->showMsg($res);
                 }
             }
         }
         $i = 0;
         if (empty($patterm)) {
             if (empty($num_arr)) {
                 while ($i < $count) {
                     $arr = "";
                     for ($j = 0; $j < $num; $j++) {
                         $arr .= $str[rand(0, hy_strlen($str) - 1)];
                     }
                     $is_exist = Model('other')->check_is_exist($arr);
                     if ($is_exist == 0) {
                         $id = Model('other')->insert_random($arr);
                         if ($id) {
                             $i++;
                         } else {
                             $res['content'] = "系统错误";
                             $this->showMsg($res);
                         }
                     }
                 }
             } else {
                 while ($i < $count) {
                     $a = 0;
                     $b = 0;
                     $c = 0;
                     $arr = "";
                     for ($j = 0; $j < $num; $j++) {
                         $status = 1;
                         while ($status) {
                             $temp = $str[rand(0, hy_strlen($str) - 1)];
                             if (strpos($str1, $temp)) {
                                 if ($a < $num_arr[0]) {
                                     $arr .= $temp;
                                     $status = 0;
                                     $a++;
                                 }
                             }
                             if (strpos($str2, $temp)) {
                                 if ($b < $num_arr[1]) {
                                     $arr .= $temp;
                                     $status = 0;
                                     $b++;
                                 }
                             }
                             if (strpos($str3, $temp)) {
                                 if ($c < $num_arr[2]) {
                                     $arr .= $temp;
                                     $status = 0;
                                     $c++;
                                 }
                             }
                         }
                     }
                     $is_exist = Model('other')->check_is_exist($arr);
                     if ($is_exist == 0) {
                         $id = Model('other')->insert_random($arr);
                         if ($id) {
                             $i++;
                         } else {
                             $res['content'] = "系统错误";
                             $this->showMsg($res);
                         }
                     }
                 }
             }
         } else {
             $patterm_type = explode("-", $patterm);
             if (count($patterm_type) == 1) {
                 $patterm_type = explode(",", $patterm);
                 if (count($patterm_type) == 1) {
                     $res['content'] = "输入的字符规则不正确,请使用“-”或者“,”";
                     $this->showMsg($res);
                 } else {
                     $patterm_code = ",";
                 }
             } else {
                 $patterm_code = "-";
             }
             $temp_num = 0;
             foreach ($patterm_type as $k => $v) {
                 $temp_num += $v;
             }
             if ($temp_num != $num) {
                 $res['content'] = "输入的字符规则数量和不正确";
                 $this->showMsg($res);
             }
             if (empty($num_arr)) {
                 while ($i < $count) {
                     $key = array();
                     foreach ($patterm_type as $kk => $vv) {
                         $arr_temp = "";
                         for ($j = 0; $j < $vv; $j++) {
                             $arr_temp .= $str[rand(0, hy_strlen($str) - 1)];
                         }
                         $key[] = $arr_temp;
                     }
                     $arr = implode($patterm_code, $key);
                     $is_exist = Model('other')->check_is_exist($arr);
                     if ($is_exist == 0) {
                         $id = Model('other')->insert_random($arr);
                         if ($id) {
                             $i++;
                         } else {
                             $res['content'] = "系统错误";
                             $this->showMsg($res);
                         }
                     }
                 }
             } else {
                 while ($i < $count) {
                     $a = 0;
                     $b = 0;
                     $c = 0;
                     $key = array();
                     foreach ($patterm_type as $kk => $vv) {
                         $arr_temp = "";
                         for ($j = 0; $j < $vv; $j++) {
                             $status = 1;
                             while ($status) {
                                 $temp = $str[rand(0, hy_strlen($str) - 1)];
                                 if (strpos($str1, $temp)) {
                                     if ($a < $num_arr[0]) {
                                         $arr_temp .= $temp;
                                         $status = 0;
                                         $a++;
                                     }
                                 }
                                 if (strpos($str2, $temp)) {
                                     if ($b < $num_arr[1]) {
                                         $arr_temp .= $temp;
                                         $status = 0;
                                         $b++;
                                     }
                                 }
                                 if (strpos($str3, $temp)) {
                                     if ($c < $num_arr[2]) {
                                         $arr_temp .= $temp;
                                         $status = 0;
                                         $c++;
                                     }
                                 }
                             }
                         }
                         $key[] = $arr_temp;
                     }
                     $arr = implode($patterm_code, $key);
                     $is_exist = Model('other')->check_is_exist($arr);
                     if ($is_exist == 0) {
                         $id = Model('other')->insert_random($arr);
                         if ($id) {
                             $i++;
                         } else {
                             $res['content'] = "系统错误";
                             $this->showMsg($res);
                         }
                     }
                 }
             }
         }
         $res = array('error' => 0, 'content' => "生成成功");
         $this->showMsg($res);
     }
     $this->display("random.html");
 }