Esempio n. 1
0
/**
 * returns random words from given array
 *
 * @param Array wordArray   array of strings
 * @param int   wordCount   quantity of words to return
 */
function pass_phrase($wordCount, $symbolCount, $digitCount)
{
    $phrase = "";
    for ($i = 0; $i < $wordCount; $i++) {
        $phrase .= random_word();
        // add symbol if all haven't been added
        if ($symbolCount > 0) {
            $phrase .= random_symbol();
        }
        // add digit if all haven't been added
        if ($digitCount > 0) {
            $phrase .= random_digit();
        }
        $symbolCount--;
        $digitCount--;
        // don't add separator to last word, add separator if no more symbols or digits
        if ($i < $wordCount - 1 && $symbolCount < 0 && $digitCount < 0) {
            $phrase .= "-";
        }
    }
    return $phrase;
}
Esempio n. 2
0
        xmail($to, $from, $data['title'], $data['comment']);
        ($code = $plugins->load('log_pwremind2_end')) ? eval($code) : null;
        ok($lang->phrase('log_pwremind_success'), "log.php?action=login" . SID2URL_x);
    }
    $slog->updatelogged();
} elseif ($_GET['action'] == "pwremind3") {
    if (flood_protect() == false) {
        error($lang->phrase('flood_control'), 'log.php?action=login' . SID2URL_x);
    }
    set_flood();
    ($code = $plugins->load('log_pwremind3_start')) ? eval($code) : null;
    $result = $db->query("SELECT id, pw, mail, name FROM {$db->pre}user WHERE id = '{$_GET['id']}' LIMIT 1", __LINE__, __FILE__);
    $user = $db->fetch_assoc($result);
    $confirmcode = md5($config['cryptkey'] . $user['pw']);
    if ($confirmcode == $_GET['fid']) {
        $pw = random_word();
        $md5 = md5($pw);
        $db->query("UPDATE {$db->pre}user SET pw = '{$md5}' WHERE id = '{$user['id']}' LIMIT 1", __LINE__, __FILE__);
        $data = $lang->get_mail('pwremind2');
        $to = array('0' => array('name' => $user['name'], 'mail' => $user['mail']));
        $from = array();
        xmail($to, $from, $data['title'], $data['comment']);
        ($code = $plugins->load('log_pwremind3_success')) ? eval($code) : null;
        ok($lang->phrase('log_pwremind_changed'), "log.php?action=login" . SID2URL_x);
    } else {
        ($code = $plugins->load('log_pwremind3_failed')) ? eval($code) : null;
        error($lang->phrase('log_pwremind_wrong_code'), "log.php?action=pwremind" . SID2URL_x);
    }
} else {
    $loc = htmlspecialchars($gpc->get('redirect', none));
    if (empty($loc)) {
Esempio n. 3
0
//@case 2. match all multiple-keywords in text :
$mp = new MultiPattern(array('abc', 'axy', 'def'));
$result = $mp->matchAll('xxxx abc def', $matches);
// $result === 2 ; $matches === array('abc', 'def')
assert(2 === $result);
assert(array('abc', 'def') == $matches);
//@case 3. build multiple-keywords to a Regular expressions
$mp = new MultiPattern(array('ab', 'abc', 'axy', 'def'));
$regex = $mp->getFullRegex();
// $regex === '/a(bc?|xy)|def/i'
assert('/a(bc?|xy)|def/i' === $regex);
//@case 4. multi-match 10000 keywords from 10000 texts
echo "10000つのキーワードを10000回テスト\n";
$keywords = array();
while (1) {
    $keywords[random_word()] = 1;
    if (count($keywords) == 10000) {
        break;
    }
}
$keywords = array_keys($keywords);
$mp = new MultiPattern($keywords);
$texts = array();
for ($i = 0; $i < 10000; $i++) {
    //キーワードが含む確率は 1/4に想定
    $tail_string = 0 == mt_rand() % 4 ? $keywords[$i] : "";
    $texts[] = base64_encode(file_get_contents('/dev/urandom', NULL, NULL, 0, 1024)) . " " . $tail_string;
}
shuffle($keywords);
//$keywordsで同じ順ではなくで検索…
$begin_time = microtime(true);
Esempio n. 4
0
 public function addRev()
 {
     require $_SERVER['DOCUMENT_ROOT'] . '/application/helpers/random_letters.php';
     $errArr = array();
     $isOk = true;
     foreach ($_POST as $post_key => $post_val) {
         switch ($post_key) {
             case 'stars':
             case 'sal':
                 if (!is_numeric($post_val) || $post_val == 0) {
                     $errArr[] = $post_key;
                     $isOk = false;
                 }
                 break;
             case 'pros':
             case 'cons':
                 if (strlen($post_val) > 100000 || $post_val == '') {
                     $errArr[] = $post_key;
                     $isOk = false;
                 }
                 break;
             case 'com':
             case 'job':
             case 'city':
                 if (strlen($post_val) > 100 || $post_val == '') {
                     $errArr[] = $post_key;
                     $isOk = false;
                 }
                 break;
         }
         $okArr[$post_key] = $post_val;
     }
     if (!$isOk) {
         echo json_encode($errArr);
     } else {
         $gen = random_word(10);
         $fileName = $_SERVER['DOCUMENT_ROOT'] . '/application/tmp_files/tmp_reviews/' . $gen;
         echo $gen;
         $f = fopen($fileName, 'w');
         chmod($fileName, 0755);
         fwrite($f, 'date=>' . date('d-m-Y') . "\n");
         fwrite($f, 'time=>' . date('h:i:s') . "\n");
         foreach ($okArr as $key => $val) {
             $val = preg_replace('/\\r\\n/', '<BR>', $val);
             $val = preg_replace('/\\n/', '<BR>', $val);
             fwrite($f, $key . '=>' . $val . "\n");
         }
         fclose($f);
     }
 }