Ejemplo n.º 1
0
/**
 * Return a random row from a database query
 *
 * @param $query
 * @param $limit
 * @return string
 */
function oos_random_select($query, $limit = '')
{

    // Get database information
    $dbconn =& oosDBGetConn();
    $oostable =& oosDBGetTables();

    $random_product = '';
    if (!empty($limit)) {
        if (USE_DB_CACHE == '1') {
            $random_result = $dbconn->CacheSelectLimit(15, $query, $limit);
        } else {
            $random_result = $dbconn->SelectLimit($query, $limit);
        }
    } else {
        if (USE_DB_CACHE == '1') {
            $random_result = $dbconn->CacheExecute(15, $query);
        } else {
            $random_result = $dbconn->Execute($query);
        }
    }
    $num_rows = $random_result->RecordCount();
    if ($num_rows > 0) {
        $random_row = oos_rand(0, ($num_rows - 1));
        $random_result->Move($random_row);
        $random_product = $random_result->fields;
    }

    return $random_product;
}
Ejemplo n.º 2
0
/**
 * This function makes a new password from a plaintext password.
 *
 * @param $sPlain
 * @return string
 */
function oos_encrypt_password($sPlain)
{
    $sPassword = '';
    for ($i = 0; $i < 10; $i++) {
        $sPassword .= oos_rand();
    }
    $sSalt = substr(md5($sPassword), 0, 2);
    $sPassword = md5($sSalt . $sPlain) . ':' . $sSalt;
    return $sPassword;
}
Ejemplo n.º 3
0
/**
 * Returns a random name, 16 to 20 characters long
 * There are more than 10^28 combinations
 * The directory is "hidden", i.e. starts with '.'
 *
 * @return  string
 */
function oos_random_name()
{
    $letters = 'abcdefghijklmnopqrstuvwxyz';
    $dirname = '.';
    $length = floor(oos_rand(16, 20));
    for ($i = 1; $i <= $length; $i++) {
        $q = floor(oos_rand(1, 26));
        $dirname .= $letters[$q];
    }
    return $dirname;
}
Ejemplo n.º 4
0
function oos_create_random_value($length, $type = 'mixed') {
    if ( ($type != 'mixed') && ($type != 'chars') && ($type != 'digits')) return false;

    $rand_value = '';
    while (strlen($rand_value) < $length) {
      if ($type == 'digits') {
        $char = oos_rand(0,9);
      } else {
        $char = chr(oos_rand(0,255));
      }
      if ($type == 'mixed') {
        if (preg_match('!^[a-z0-9]$!', $char)) $rand_value .= $char;
      } elseif ($type == 'chars') {
        if (preg_match('!^[a-z]$!', $char)) $rand_value .= $char;
      } elseif ($type == 'digits') {
        if (preg_match('!^[0-9]$!', $char)) $rand_value .= $char;
      }
    }

    return $rand_value;
}