Example #1
0
function mnemonic($chars, $numbers)
{
    $letters = array(0 => array('q', 'w', 'r', 'g', 'f', 'd', 's', 'z', 'x', 'c', 'v'), 1 => array('u', 'i', 'o'), 2 => array('y', 'p', 'h', 'j', 'k', 'l', 'b', 'n', 'm'), 3 => array('e', 'a'));
    $digits = array(0 => array('1', '2', '3', '4', '5', '6'), 1 => array('7', '8', '9', '0'));
    for ($i = 0; $i < $chars; $i++) {
        $pass .= $letters[$i % 4][array_rand($letters[$i % 4])];
    }
    $dirty_words = array('bob', 'con', 'cum', 'fod', 'fuc', 'fud', 'fuk', 'gal', 'gat', 'mal', 'mam', 'mar', 'mec', 'pat', 'peg', 'per', 'pic', 'pil', 'pit', 'put', 'rab', 'tar', 'tes', 'tet', 'tol', 'vac', 'images', 'js', 'css', 'Services');
    foreach ($dirty_words as $dirty_word) {
        if (strpos($pass, $dirty_word) !== false) {
            return mnemonic($chars, $numbers);
        }
    }
    if ($numbers > 0) {
        for ($i = 0; $i < $numbers; $i++) {
            $pass .= $digits[$i % 2][array_rand($digits[$i % 2])];
        }
    }
    return $pass;
}
Example #2
-2
function register_url($url)
{
    global $tag_length;
    global $MYSQL_TABLE_REDIRECTIONS;
    global $logged_in;
    $newtag = mnemonic($tag_length, 0);
    //echo $newtag;
    $query = "SELECT url FROM " . $MYSQL_TABLE_REDIRECTIONS . " WHERE tag='" . mysql_real_escape_string($newtag) . "';";
    //echo $query;
    //exit();
    while (!mysql_query($query)) {
        //keep trying till a random tag which is not already in DB is found
        //TODO: A do-while loop would have been nicer
        $newtag = mnemonic($tag_length, 0);
        $query = "SELECT url FROM " . $MYSQL_TABLE_REDIRECTIONS . " WHERE tag='" . mysql_real_escape_string($newtag) . "';";
    }
    //now we have our tag, we have our URL, we have to get other information
    $tagger = "";
    if ($logged_in) {
        $tagger = $_SESSION['OPENID_IDENTITY'];
    } else {
        $tagger = 'guest';
    }
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date_now = $mysqldate = date('Y-m-d H:i:s');
    $query = "INSERT INTO " . $MYSQL_TABLE_REDIRECTIONS . " value('{$newtag}','{$url}','{$tagger}','{$ipaddress}','{$date_now}',0);";
    if (mysql_query($query)) {
        return $newtag;
    } else {
        die("Cannot insert into Database for URL: {$url} and tag:{$newtag}");
        return false;
    }
}