Esempio n. 1
0
/**
 * 根据邮箱地址生成用户名
 *
 * @param number $length
 * @return number
 */
function generate_username()
{
    $username = '******' . rand_number(3);
    $charts = "ABCDEFGHJKLMNPQRSTUVWXYZ";
    $max = strlen($charts);
    for ($i = 0; $i < 4; $i++) {
        $username .= $charts[mt_rand(0, $max)];
    }
    $username .= rand_number(4);
    $sql = "select count(*) from " . $GLOBALS['ecs']->table('users') . " where user_name = '{$username}'";
    $count = $GLOBALS['db']->getOne($sql);
    if ($count > 0) {
        return generate_username();
    }
    return $username;
}
Esempio n. 2
0
/**
 * 发送手机验证所需的短信验证码
 */
function action_send_mobile_code()
{
    $_LANG = $GLOBALS['_LANG'];
    $smarty = $GLOBALS['smarty'];
    $db = $GLOBALS['db'];
    $ecs = $GLOBALS['ecs'];
    require_once ROOT_PATH . 'includes/lib_validate_record.php';
    $mobile_phone = trim($_SESSION[VT_MOBILE_VALIDATE]);
    if (empty($mobile_phone)) {
        exit("手机号不能为空");
        return;
    } else {
        if (!is_mobile_phone($mobile_phone)) {
            exit("手机号格式不正确");
            return;
        } else {
            if (check_validate_record_exist($mobile_phone)) {
                // 获取数据库中的验证记录
                $record = get_validate_record($mobile_phone);
                /**
                 * 检查是过了限制发送短信的时间
                 */
                $last_send_time = $record['last_send_time'];
                $expired_time = $record['expired_time'];
                $create_time = $record['create_time'];
                $count = $record['count'];
                // 每天每个手机号最多发送的验证码数量
                $max_sms_count = 10;
                // 发送最多验证码数量的限制时间,默认为24小时
                $max_sms_count_time = 60 * 60 * 24;
                if (time() - $last_send_time < 60) {
                    echo "每60秒内只能发送一次短信验证码,请稍候重试";
                    return;
                } else {
                    if (time() - $create_time < $max_sms_count_time && $record['count'] > $max_sms_count) {
                        echo "您发送验证码太过于频繁,请稍后重试!";
                        return;
                    } else {
                        $count++;
                    }
                }
            }
        }
    }
    require_once ROOT_PATH . 'includes/lib_passport.php';
    // 设置为空
    $_SESSION[VT_MOBILE_VALIDATE] = array();
    require_once ROOT_PATH . 'sms/sms.php';
    // 生成6位短信验证码
    $mobile_code = rand_number(6);
    // 短信内容
    $content = sprintf($_LANG['mobile_code_template'], $GLOBALS['_CFG']['shop_name'], $mobile_code, $GLOBALS['_CFG']['shop_name']);
    /* 发送激活验证邮件 */
    $result = sendSMS($mobile_phone, $content);
    // 	$result = true;
    if ($result) {
        if (!isset($count)) {
            $ext_info = array("count" => 1);
        } else {
            $ext_info = array("count" => $count);
        }
        // 保存验证的手机号
        $_SESSION[VT_MOBILE_VALIDATE] = $mobile_phone;
        // 保存验证信息
        save_validate_record($mobile_phone, $mobile_code, VT_MOBILE_VALIDATE, time(), time() + 30 * 60, $ext_info);
        echo 'ok';
    } else {
        echo '短信验证码发送失败';
    }
}
Esempio n. 3
0
 /**
  * ランダムな文字列を返す
  * @param  integer $max [description]
  * @return [type]       [description]
  */
 static function rand_string($max = 32)
 {
     return substr(md5(uniqid(rand_number(), true)), 0, $max);
 }
Esempio n. 4
0
/**
 * 生成随机的用户名
 * 
 * @return string 用户名
 */
function generate_username()
{
    include_once ROOT_PATH . 'includes/lib_passport.php';
    $username = '';
    while (true) {
        $number = rand_number(5) . rand_number(5);
        $username = '******' . $number;
        $exist = check_username_exist($username);
        if (!$exist) {
            break;
        }
    }
    return $username;
}
Esempio n. 5
0
 } else {
     $warnings = array();
 }
 // 入力データを検証&登録
 if (isset($_POST['_type']) && $_POST['_type'] === 'json') {
     if (empty($warnings)) {
         ok();
     } else {
         warning($warnings);
     }
 } else {
     if (empty($warnings)) {
         // トランザクションを開始
         db_transaction();
         // パスワード再発行用URLを通知
         $resource = update_users(array('set' => array('token' => rand_string(), 'token_code' => rand_number(1000, 9999), 'token_expire' => localdate('Y-m-d H:i:s', time() + 60 * 60 * 24)), 'where' => array('email = :email', array('email' => $_POST['email']))));
         if (!$resource) {
             error('指定されたメールアドレスが見つかりません。');
         }
         $users = select_users(array('where' => array('email = :email', array('email' => $_POST['email']))));
         // メール送信内容を作成
         $_view['url'] = $GLOBALS['config']['http_url'] . MAIN_FILE . '/password/form?key=' . rawurlencode($users[0]['email']) . '&token=' . $users[0]['token'];
         $_SESSION['expect']['token_code'] = $users[0]['token_code'];
         $to = $users[0]['email'];
         $subject = $GLOBALS['config']['mail_subjects']['password/send'];
         $message = view('mail/password/send.php', true);
         $headers = $GLOBALS['config']['mail_headers'];
         // メールを送信
         if (service_mail_send($to, $subject, $message, $headers) === false) {
             error('メールを送信できません。');
         }