Beispiel #1
0
 private static function _autorize($row)
 {
     global $db;
     $_SESSION['user_id'] = $row['id'];
     $_SESSION['user_name'] = $row['name'];
     $_SESSION['company_id'] = $row['company_id'];
     $_SESSION['domain'] = $row['domain'];
     // установим переменную сессии user_as_agency
     // значение 1 - если пользователь не привязан к какой-либо компании (является риелтором),
     //              либо является пользователем, привязанным к агенству недвижимости
     if (!isset($row['company_id']) || isset($row['company_type_id']) && $row['company_type_id'] == Company::COMPANY_TYPE_AGENCY) {
         $_SESSION['user_as_agency'] = 1;
     }
     if ($row['company_name'] != '') {
         $_SESSION['user_name'] .= ' (' . $row['company_name'] . ')';
     }
     $_SESSION['user_tariff_id'] = $row['tariff_id'];
     $key = getRandomStr(ADDON_HASH) . '' . md5($row['id']);
     if (!isset($_COOKIE['hx'])) {
         setcookie('hx', $key);
         $hash_sql = ", hash='{$key}'";
     } else {
         $hash_sql = '';
     }
     $db->query("UPDATE user SET last_login=NOW() {$hash_sql} WHERE id=" . $row['id']);
 }
Beispiel #2
0
function getUniqueRandomStr($existing, $len)
{
    // Generates a random string and checks against array of existing strings
    $result = NULL;
    do {
        $result = getRandomStr($len);
    } while (in_array($result, $existing));
    return $result;
}
Beispiel #3
0
 public function register()
 {
     if (!$this->input->is_ajax_request()) {
         $jsonData = array('code' => -1, 'msg' => "非法请求");
         echo json_encode($jsonData);
         exit;
     }
     // 用户名
     $userName = $this->input->post('user_name');
     if ("" == $userName) {
         $jsonData = array('code' => -2, 'msg' => '用户名不能为空');
         echo json_encode($jsonData);
         exit;
     }
     //todo 验证用户名是否存在
     //todo 验证邮箱是否存在
     // 邮箱
     $email = $this->input->post('email');
     if ("" == $email) {
         $jsonData = array('code' => -3, 'msg' => '邮箱不能为空');
         echo json_encode($jsonData);
         exit;
     }
     // 密码
     $password = $this->input->post('password');
     if ("" == $password) {
         $jsonData = array('code' => -4, 'msg' => '密码不能为空');
         echo json_encode($jsonData);
         exit;
     }
     // 验证码
     $authcode = trim($this->input->post('authcode'));
     if ($authcode == "") {
         $jsonData = array('code' => -5, 'msg' => '验证码不能为空');
         echo json_encode($jsonData);
         exit;
     }
     if (!$this->authcode->check($authcode)) {
         $jsonData = array('code' => -6, 'msg' => '验证码错误');
         echo json_encode($jsonData);
         exit;
     }
     // saveData
     $randomStr = getRandomStr();
     $saveData = array('user_name' => $userName, 'email' => $email, 'password' => getUserPassword($password, $randomStr), 'salt' => $randomStr, 'ip' => isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : "");
     if ($this->web_user_model->addUser($saveData)) {
         $jsonData = array('code' => 1, 'msg' => '注册成功');
         echo json_encode($jsonData);
         exit;
     } else {
         $jsonData = array('code' => 0, 'msg' => '注册失败');
         echo json_encode($jsonData);
         exit;
     }
 }
Beispiel #4
0
/**
 * To generate the encrypted password
 *
 * @param  $str
 * @return string
 */
function getCryptHash($str)
{
    if (CRYPT_BLOWFISH) {
        if (version_compare(PHP_VERSION, '5.3.7') >= 0) {
            // http://www.php.net/security/crypt_blowfish.php
            $algo_selector = '$2y$';
        } else {
            $algo_selector = '$2a$';
        }
        $workload_factor = '12$';
        // (around 300ms on Core i7 machine)
        $salt = $algo_selector . $workload_factor . getRandomStr(array_merge(array('.', '/'), range('0', '9'), range('a', 'z'), range('A', 'Z')), 22);
        // './0-9A-Za-z'
    } else {
        if (CRYPT_MD5) {
            $algo_selector = '$1$';
            $salt = $algo_selector . getRandomStr(range(chr(33), chr(127)), 12);
            // actually chr(0) - chr(255), but used ASCII only
        } else {
            if (CRYPT_SHA512) {
                $algo_selector = '$6$';
                $workload_factor = 'rounds=5000$';
                $salt = $algo_selector . $workload_factor . getRandomStr(range(chr(33), chr(127)), 16);
                // actually chr(0) - chr(255)
            } else {
                if (CRYPT_SHA256) {
                    $algo_selector = '$5$';
                    $workload_factor = 'rounds=5000$';
                    $salt = $algo_selector . $workload_factor . getRandomStr(range(chr(33), chr(127)), 16);
                    // actually chr(0) - chr(255)
                } else {
                    if (CRYPT_EXT_DES) {
                        $algo_selector = '_';
                        $salt = $algo_selector . getRandomStr(array_merge(array('.', '/'), range('0', '9'), range('a', 'z'), range('A', 'Z')), 8);
                        // './0-9A-Za-z'.
                    } else {
                        if (CRYPT_STD_DES) {
                            $algo_selector = '';
                            $salt = $algo_selector . getRandomStr(array_merge(array('.', '/'), range('0', '9'), range('a', 'z'), range('A', 'Z')), 2);
                            // './0-9A-Za-z'
                        }
                    }
                }
            }
        }
    }
    return crypt($str, $salt);
}
Beispiel #5
0
function getNewImageName()
{
    $allImageNames = getAllImageNames();
    do {
        $newImageName = getRandomStr(8);
    } while (array_key_exists($newImageName, $allImageNames));
    return $newImageName;
}
Beispiel #6
0
// $plat_from	= strtoupper($_GET['plat']);
//获取token值
$reqHandler = new RequestHandler();
$reqHandler->init($APP_ID, $APP_SECRET, $PARTNER_KEY);
//=========================
//生成预支付单
//=========================
//设置packet支付参数
$packetParams = array();
//公众账号ID
$packetParams['appid'] = $APP_ID;
//商户号
$packetParams['mch_id'] = $PARTNER;
//设备号  TODO
$packetParams['device_info'] = $device_info;
$nonce_str = getRandomStr();
//随机字符串
$packetParams['nonce_str'] = $nonce_str;
//商品描述
$packetParams['body'] = $product_name;
//商品详情
$packetParams['attach'] = $product_name;
//商户订单号
$packetParams['out_trade_no'] = $out_trade_no;
//总金额
$packetParams['total_fee'] = $total_fee;
//访问接口IP
//$packetParams['spbill_create_ip'] = Request::getClientIp();
$packetParams['spbill_create_ip'] = '127.0.0.1';
//接受微信支付异步通知回调地址
$packetParams['notify_url'] = ecmobile_url() . $notify_url;