Ejemplo n.º 1
0
 protected function buildEmailVerify($length = 20, $mode = 5, $verifyName = 'emailVerify')
 {
     import('ORG.Util.String');
     $verify = String::rand_string($length, $mode);
     $_SESSION[$verifyName] = md5($verify);
     return $verify;
 }
Ejemplo n.º 2
0
 /**
 +----------------------------------------------------------
 *  带格式生成随机字符 支持批量生成
 *  但可能存在重复
 +----------------------------------------------------------
 * @param string $format 字符格式
 *     # 表示数字 * 表示字母和数字 $ 表示字母
 * @param integer $number 生成数量
 +----------------------------------------------------------
 * @return string | array
 +----------------------------------------------------------
 */
 public static function build_format_rand($format, $number = 1)
 {
     $str = array();
     $length = strlen($format);
     for ($j = 0; $j < $number; $j++) {
         $strtemp = '';
         for ($i = 0; $i < $length; $i++) {
             $char = substr($format, $i, 1);
             switch ($char) {
                 case "*":
                     //字母和数字混合
                     $strtemp .= String::rand_string(1);
                     break;
                 case "#":
                     //数字
                     $strtemp .= String::rand_string(1, 1);
                     break;
                 case "\$":
                     //大写字母
                     $strtemp .= String::rand_string(1, 2);
                     break;
                 default:
                     //其他格式均不转换
                     $strtemp .= $char;
                     break;
             }
         }
         $str[] = $strtemp;
     }
     return $number == 1 ? $strtemp : $str;
 }
Ejemplo n.º 3
0
 static function GBVerify($length = 4, $type = 'png', $width = 180, $height = 50, $fontface = 'simhei.ttf', $verifyName = 'verify')
 {
     include_once LIB_PATH . '/Misc/String.class.php';
     $code = String::rand_string($length, 4);
     $width = $length * 45 > $width ? $length * 45 : $width;
     $_SESSION[$verifyName] = md5($code);
     $im = imagecreatetruecolor($width, $height);
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     $bkcolor = imagecolorallocate($im, 250, 250, 250);
     imagefill($im, 0, 0, $bkcolor);
     @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     // 干扰
     for ($i = 0; $i < 15; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     for ($i = 0; $i < 255; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $fontcolor);
     }
     if (!is_file($fontface)) {
         $fontface = dirname(__FILE__) . "/" . $fontface;
     }
     for ($i = 0; $i < $length; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 120), mt_rand(0, 120), mt_rand(0, 120));
         //这样保证随机出来的颜色较深。
         $codex = String::msubstr($code, $i, 1);
         imagettftext($im, mt_rand(16, 20), mt_rand(-60, 60), 40 * $i + 20, mt_rand(30, 35), $fontcolor, $fontface, $codex);
     }
     Image::output($im, $type);
 }
Ejemplo n.º 4
0
/**
 * 对用户的密码进行加密
 *
 * @param $password
 * @param $encrypt //传入加密串,在修改密码时做认证
 * @return array/password
 */
function password($password, $encrypt = '')
{
    $pwd = array();
    $pwd['encrypt'] = $encrypt ? $encrypt : String::rand_string(6);
    $pwd['password'] = md5(md5(trim($password)) . $pwd['encrypt']);
    return $encrypt ? $pwd['password'] : $pwd;
}
Ejemplo n.º 5
0
 /**
 +----------------------------------------------------------
 * 生成图像验证码
 +----------------------------------------------------------
 * @static
 * @access public
 +----------------------------------------------------------
 * @param string $length  位数
 * @param string $mode  类型
 * @param string $type 图像格式
 * @param string $width  宽度
 * @param string $height  高度
 +----------------------------------------------------------
 * @return string
 +----------------------------------------------------------
 */
 static function buildImageVerify($length = 4, $mode = 1, $type = 'png', $width = 48, $height = 22, $verifyName = 'verify')
 {
     import('@.ORG.String');
     $randval = String::rand_string($length, $mode);
     $_SESSION[$verifyName] = md5($randval);
     $width = $length * 10 + 10 > $width ? $length * 10 + 10 : $width;
     if ($type != 'gif' && function_exists('imagecreatetruecolor')) {
         $im = @imagecreatetruecolor($width, $height);
     } else {
         $im = @imagecreate($width, $height);
     }
     $r = array(225, 255, 255, 223);
     $g = array(225, 236, 237, 255);
     $b = array(225, 236, 166, 125);
     $key = mt_rand(0, 3);
     $backColor = imagecolorallocate($im, $r[$key], $g[$key], $b[$key]);
     //背景色(随机)
     $borderColor = imagecolorallocate($im, 100, 100, 100);
     //边框色
     $pointColor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
     //点颜色
     @imagefilledrectangle($im, 0, 0, $width - 1, $height - 1, $backColor);
     @imagerectangle($im, 0, 0, $width - 1, $height - 1, $borderColor);
     $stringColor = imagecolorallocate($im, mt_rand(0, 200), mt_rand(0, 120), mt_rand(0, 120));
     // 干扰
     for ($i = 0; $i < 10; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagearc($im, mt_rand(-10, $width), mt_rand(-10, $height), mt_rand(30, 300), mt_rand(20, 200), 55, 44, $fontcolor);
     }
     for ($i = 0; $i < 25; $i++) {
         $fontcolor = imagecolorallocate($im, mt_rand(0, 255), mt_rand(0, 255), mt_rand(0, 255));
         imagesetpixel($im, mt_rand(0, $width), mt_rand(0, $height), $pointColor);
     }
     for ($i = 0; $i < $length; $i++) {
         imagestring($im, 5, $i * 10 + 5, mt_rand(1, 8), $randval[$i], $stringColor);
     }
     //        @imagestring($im, 5, 5, 3, $randval, $stringColor);
     Image::output($im, $type);
 }
Ejemplo n.º 6
0
 /**
  * @Title: sendAuditMsg
  * @Description: todo(手机短信发送)
  * @param int $id 当前模型数据ID
  * @param string $m  控制器名称
  * @param id $userid 后台用户ID
  * @param unknown_type $systemtype
  * @author liminggang
  * @date 2013-7-12 下午4:41:45
  * @throws
  */
 public function sendAuditMsg($id = "", $m = "", $userid = "", $systemtype = 0)
 {
     $md = $m ? $m : $this->getActionName();
     //第一步、获取需要发送的短信内容
     $content = $this->setProcessModelMesg($md, $id);
     //第二步、获取系统自带的内容,在判断内容大小
     import('@.ORG.String');
     $code = String::rand_string(4, 1);
     //第三步、验证回复验证码是否有重复
     $MessageVerifyDao = M('message_verify');
     $map = array();
     $map['code'] = $code;
     $map['isreply'] = 0;
     $count = $MessageVerifyDao->where($map)->count("*");
     while ($count > 0) {
         $code = String::rand_string(4, 1);
         $map = array();
         $map['code'] = $code;
         $map['isreply'] = 0;
         $count = $MessageVerifyDao->where($map)->count("*");
     }
     //第四步、根据后台用户ID获取用户手机号码(这里必须获取的是通过验证的手机号码)
     $UserDao = M('user');
     $map = array();
     $map['mobilestatus'] = 1;
     $map['id'] = $userid;
     $mobile = $UserDao->where($map)->field("mobile")->find();
     if (!$mobile) {
         $this->error("此用户的手机未通过验证!不能发送短信");
     }
     $data['code'] = $code;
     $data["tablename"] = $md;
     $data["tableid"] = $id;
     $data["replyuser"] = $userid;
     $data["replytel"] = $mobile['mobile'];
     $data["createtime"] = time();
     $re = $MessageVerifyDao->add($data);
     if ($re) {
         //限制发送内容长度在240个字符内,如果超出了则用...替代
         $content .= " 回复" . $code . "01+批复内容 批复; 回复" . $code . "00+批复内容 打回";
         $remsg = $this->SendTelmMsg($content, $data["replytel"], $systemtype);
         $msgstatus = intval(trim($remsg));
         if ($msgstatus != 1 && $msgstatus != 0) {
             $this->error("短信发送失败" . $msgstatus);
         }
     } else {
         $this->error("操作失败");
     }
     //$r="||15123132519#123456#1同意#2013-07-10 17:33:55#";
     //$this->success ( L('_SUCCESS_') );
 }
Ejemplo n.º 7
0
 private function formatContent($content, $data, $type)
 {
     switch ($type) {
         case 1:
         case 2:
         case 4:
         case 5:
             $content = str_replace('{rand}', $data['rand'], $this->_defaultHash[$type]);
             break;
         case 3:
             tsload(ADDON_PATH . 'brary/String.class.php');
             $rndstr = String::rand_string(5, 3);
             $pwd = $rndstr . $data['rand'];
             $content = str_replace('{pwd}', $pwd, $this->_defaultHash[$type]);
             $map['login'] = $data['communication'];
             $uname = model('User')->where($map)->getField('uname');
             $content = str_replace('{name}', $uname, $content);
             $setuser['login_salt'] = rand(10000, 99999);
             $setuser['password'] = md5(md5($pwd) . $setuser['login_salt']);
             model('User')->where($map)->save($setuser);
             break;
     }
     return $content;
 }
Ejemplo n.º 8
0
     $database = C('database', 'default');
     $testdata = $_POST['testdata'];
     $selectapp = $_POST['selectapp'];
     include INS_PATH . "step/step_" . $step . ".tpl.php";
     break;
 case '6':
     // 安装详细过程
     $db_config = array('hostname' => $_POST['dbhost'], 'username' => $_POST['dbuser'], 'password' => $_POST['dbpw'], 'database' => $_POST['dbname'], 'prefix' => $_POST['prefix'], 'pconnect' => $_POST['pconnect'], 'charset' => $_POST['dbcharset']);
     \Leaps\Base\Config::modify('database', $db_config);
     // 写入数据库配置信息
     \Leaps\Base\Config::modify('cookie', array('prefix' => String::rand_string(5) . '_'));
     // Cookie前缀
     // 附件访问路径
     \Leaps\Base\Config::modify('attachment', array('upload_url' => $siteurl . 'data/attachment/'));
     \Leaps\Base\Config::modify('attachment', array('avatar_url' => $siteurl . 'data/avatar/'));
     $auth_key = String::rand_string(20);
     \Leaps\Base\Config::modify('config', array('auth_key' => $auth_key));
     $uuid = String::uuid(C('version', 'product') . '-');
     \Leaps\Base\Config::modify('version', array('uuid' => $uuid));
     \Leaps\Base\Config::modify('system', array('js_path' => $siteurl . 'statics/js/', 'css_path' => $siteurl . 'statics/css/', 'img_path' => $siteurl . 'statics/images/', 'app_path' => $siteurl, 'skin_path' => $siteurl . 'statics/skins/'));
     $selectapp = $_POST['selectapp'];
     $testdata = $_POST['testdata'];
     include INS_PATH . "step/step_" . $step . ".tpl.php";
     break;
 case '7':
     // 完成安装
     //File::write ( DATA_PATH . 'install.lock', 'ok' );
     include INS_PATH . "step/step_" . $step . ".tpl.php";
     //Folder::rm(INS_PATH);//删除安装目录
     break;
 case 'installapp':
Ejemplo n.º 9
0
 public function sendPasswordApi($tel)
 {
     //发送注册短信
     $tel = t($tel);
     if (!$tel) {
         return false;
     }
     $data['Mobile'] = $tel;
     $data['Rand'] = rand(11111, 99999);
     $data['Type'] = 3;
     $data['Status'] = 0;
     $data['level'] = 0;
     $data['AddDate'] = date('Y-m-d H:i:s');
     tsload(ADDON_PATH . 'brary/String.class.php');
     $rndstr = String::rand_string(5, 3);
     $pwd = $rndstr . $data['Rand'];
     $data['smsContent'] = '亲爱的用户,您的当前密码为:' . $pwd;
     $res = $this->add($data);
     $map['login'] = $tel;
     $setuser['login_salt'] = rand(10000, 99999);
     $setuser['password'] = md5(md5($pwd) . $setuser['login_salt']);
     $res = model('User')->where($map)->save($setuser);
     return $res;
 }
Ejemplo n.º 10
0
 /**
  * 添加会员
  */
 public function add()
 {
     header("Cache-control: private");
     if (isset($_POST['dosubmit'])) {
         $info = array();
         if ($this->api->check_username($_POST['info']['username']) != 1) {
             showmessage(L('member_exist'));
         }
         $info = $this->_checkuserinfo($_POST['info']);
         if (!Validate::is_password($info['password'])) {
             showmessage(L('password_format_incorrect'));
         }
         $info['encrypt'] = String::rand_string(6);
         $info['regip'] = IP;
         $info['overduedate'] = isset($info['overduedate']) && !empty($info['overduedate']) ? strtotime($info['overduedate']) : 0;
         unset($info['pwdconfirm']);
         $info['regdate'] = $info['lastdate'] = TIME;
         $userid = $this->api->add($info);
         if ($userid > 0) {
             showmessage(L('operation_success'), U('member/member/add'), '', 'add');
         } else {
             switch ($userid) {
                 case '-1':
                     showmessage(L('username_illegal'), HTTP_REFERER);
                     // 用户名不合法
                     break;
                 case '-2':
                     showmessage(L('username_deny'), HTTP_REFERER);
                     // 用户名包含不允许注册的词语
                     break;
                 case '-3':
                     showmessage(L('member_exist'), HTTP_REFERER);
                     // 用户名已存在
                     break;
                 case '-4':
                     showmessage(L('email_illegal'), HTTP_REFERER);
                     // E-mail不合法
                     break;
                 case '-5':
                     showmessage(L('email_deny'), HTTP_REFERER);
                     // E-mail不允许注册
                     break;
                 case '-6':
                     showmessage(L('email_already_exist'), HTTP_REFERER);
                     // 该Email已经被注册
                     break;
                 case '-7':
                     showmessage(L('operation_failure'), HTTP_REFERER);
                     break;
             }
         }
     } else {
         $show_header = $show_scroll = true;
         // 会员组缓存
         $group_cache = S('member/grouplist');
         foreach ($group_cache as $_key => $_value) {
             $grouplist[$_key] = $_value['name'];
         }
         // 会员模型缓存
         $member_model_cache = S('common/member_model');
         foreach ($member_model_cache as $_key => $_value) {
             $modellist[$_key] = $_value['name'];
         }
         include $this->view('member_add');
     }
 }
Ejemplo n.º 11
0
 /**
  * 找回密码
  */
 public function public_forget_password()
 {
     if (isset($_POST['dosubmit'])) {
         $checkcode = isset($_POST['code']) && trim($_POST['code']) ? trim($_POST['code']) : showmessage(L('input_code'), HTTP_REFERER);
         if (!checkcode($checkcode)) {
             // 判断验证码
             showmessage(L('code_error'), HTTP_REFERER);
         }
         $memberinfo = $this->db->getby_email($_POST['email']);
         if (!empty($memberinfo['email'])) {
             $email = $memberinfo['email'];
         } else {
             showmessage(L('email_error'), HTTP_REFERER);
         }
         $code = String::authcode($memberinfo['userid'] . "\t" . TIME, 'ENCODE', $this->auth_key);
         $url = SITE_URL . "index.php?app=member&controller=passport&action=public_forget_password&code={$code}";
         $message = $this->member_setting['forgetpassword'];
         $message = str_replace(array('{click}', '{url}'), array('<a href="' . $url . '">' . L('please_click') . '</a>', $url), $message);
         sendmail($email, L('forgetpassword'), $message);
         showmessage(L('operation_success'), 'index.php?app=member&controller=passport&action=login');
     } elseif (isset($_GET['code'])) {
         $hour = date('y-m-d h', TIME);
         $code = String::authcode($_GET['code'], 'DECODE', $this->auth_key);
         $code = explode("\t", $code);
         if (is_array($code) && is_numeric($code[0]) && date('y-m-d h', TIME) == date('y-m-d h', $code[1])) {
             $memberinfo = $this->db->getby_userid($code[0]);
             $password = String::rand_string(8);
             $updateinfo['password'] = password($password, $memberinfo['encrypt']);
             $this->db->where(array('userid' => $code[0]))->update($updateinfo);
             if (!is_null($this->api->uc) && !empty($memberinfo['ucenterid'])) {
                 $this->api->uc->uc_user_edit($memberinfo['username'], '', $password, '', 1);
             }
             showmessage(L('operation_success') . L('newpassword') . ':' . $password);
         } else {
             showmessage(L('operation_failure'), 'index.php?app=member&controller=passport&action=login');
         }
     } else {
         $siteinfo = S('common/common');
         include template('member', 'forget_password');
     }
 }
Ejemplo n.º 12
0
 public function download()
 {
     $a_k = trim($_GET['a_k']);
     $yun_auth_key = md5($this->auth_key . $_SERVER['HTTP_USER_AGENT']);
     $a_k = String::authcode($a_k, 'DECODE', $yun_auth_key);
     if (empty($a_k)) {
         showmessage(L('illegal_parameters'));
     }
     unset($i, $m, $f, $t, $ip);
     parse_str($a_k);
     if (isset($i)) {
         $downid = intval($i);
     }
     if (!isset($m)) {
         showmessage(L('illegal_parameters'));
     }
     if (!isset($modelid)) {
         showmessage(L('illegal_parameters'));
     }
     if (empty($f)) {
         showmessage(L('url_invalid'));
     }
     if (!$i || $m < 0) {
         showmessage(L('illegal_parameters'));
     }
     if (!isset($t)) {
         showmessage(L('illegal_parameters'));
     }
     if (!isset($ip)) {
         showmessage(L('illegal_parameters'));
     }
     $starttime = intval($t);
     if (preg_match('/(php|phtml|php3|php4|jsp|dll|asp|cer|asa|shtml|shtm|aspx|asax|cgi|fcgi|pl)(\\.|$)/i', $f) || strpos($f, ":\\") !== FALSE || strpos($f, '..') !== FALSE) {
         showmessage(L('url_error'));
     }
     $fileurl = trim($f);
     if (!isset($downid) || empty($fileurl) || !preg_match("/[0-9]{10}/", $starttime) || !preg_match("/[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}/", $ip) || $ip != IP) {
         showmessage(L('illegal_parameters'));
     }
     $endtime = TIME - $starttime;
     if ($endtime > 3600) {
         showmessage(L('url_invalid'));
     }
     if ($m) {
         $fileurl = trim($s) . trim($fileurl);
     }
     //远程文件
     if (strpos($fileurl, ':/') && strpos($fileurl, C('attachment', 'upload_url')) === false) {
         header("Location: {$fileurl}");
     } else {
         if ($d == 0) {
             header("Location: " . $fileurl);
         } else {
             $fileurl = str_replace(array(C('attachment', 'upload_url'), '/'), array(C('attachment', 'upload_path'), DIRECTORY_SEPARATOR), $fileurl);
             $filename = basename($fileurl);
             //处理中文文件
             if (preg_match("/^([\\s\\S]*?)([�-�][@-�])([\\s\\S]*?)/", $fileurl)) {
                 $filename = str_replace(array("%5C", "%2F", "%3A"), array("\\", "/", ":"), urlencode($fileurl));
                 $filename = urldecode(basename($filename));
             }
             $ext = File::get_suffix($filename);
             $filename = date('Ymd_his') . String::rand_string(3) . '.' . $ext;
             File::down($fileurl, $filename);
         }
     }
 }
Ejemplo n.º 13
0
 /**
  * 生成随机验证码。
  */
 public function creat_code()
 {
     $this->response = String::rand_string(4);
     Loader::session();
     $_SESSION['code'] = strtolower($this->response);
 }