function smn_encrypt_password($plain)
{
    $password = '';
    for ($i = 0; $i < 10; $i++) {
        $password .= smn_rand();
    }
    $salt = substr(md5($password), 0, 2);
    $password = md5($salt . $plain) . ':' . $salt;
    return $password;
}
Example #2
0
function smn_random_name()
{
    $letters = 'abcdefghijklmnopqrstuvwxyz';
    $dirname = '.';
    $length = floor(smn_rand(16, 20));
    for ($i = 1; $i <= $length; $i++) {
        $q = floor(smn_rand(1, 26));
        $dirname .= $letters[$q];
    }
    return $dirname;
}
Example #3
0
 /**
  * encode()
  * 
  * Encodes and returns the email. Also stores
  * it in the encoded member variable
  *
  * @return An associative array containing two elements,
  *         body and headers. The headers element is itself
  *         an indexed array.
  * @access public
  */
 function encode()
 {
     /* HPDL PHP3 */
     //      $encoded =& $this->_encoded;
     $encoded = $this->_encoded;
     if (smn_not_null($this->_subparts)) {
         $boundary = '=_' . md5(uniqid(smn_rand()) . microtime());
         $this->_headers['Content-Type'] .= ';' . $this->lf . chr(9) . 'boundary="' . $boundary . '"';
         // Add body parts to $subparts
         for ($i = 0; $i < count($this->_subparts); $i++) {
             $headers = array();
             /* HPDL PHP3 */
             //          $tmp = $this->_subparts[$i]->encode();
             $_subparts = $this->_subparts[$i];
             $tmp = $_subparts->encode();
             reset($tmp['headers']);
             while (list($key, $value) = each($tmp['headers'])) {
                 $headers[] = $key . ': ' . $value;
             }
             $subparts[] = implode($this->lf, $headers) . $this->lf . $this->lf . $tmp['body'];
         }
         $encoded['body'] = '--' . $boundary . $this->lf . implode('--' . $boundary . $this->lf, $subparts) . '--' . $boundary . '--' . $this->lf;
     } else {
         $encoded['body'] = $this->_getEncodedData($this->_body, $this->_encoding) . $this->lf;
     }
     // Add headers to $encoded
     /* HPDL PHP3 */
     //      $encoded['headers'] =& $this->_headers;
     $encoded['headers'] = $this->_headers;
     return $encoded;
 }
Example #4
0
function session_start()
{
    global $session, $SID, $HTTP_COOKIE_VARS, $_GET, $_POST;
    // Define the global variable $SID?
    $define_sid = true;
    // Send the session cookie?
    $send_cookie = true;
    // Is track_vars enabled?
    $track_vars = isset($HTTP_COOKIE_VARS) || isset($_GET) || isset($_POST) ? true : false;
    // Check if session_start() has been called once already
    if ($session->nr_open_sessions != 0) {
        return false;
    }
    // If our only resource is the global symbol_table, then check it.
    // If track_vars are enabled, we prefer these, because they are more
    // reliable, and we always know whether the user has accepted the
    // cookie.
    if (isset($GLOBALS[$session->name]) && !empty($GLOBALS[$session->name]) && !$track_vars) {
        $session->id = $GLOBALS[$session->name];
        $send_cookie = false;
    }
    // Now check the track_vars. Cookies are preferred, because initially
    // cookie and get variables will be available.
    if (empty($session->id) && $track_vars) {
        if (isset($HTTP_COOKIE_VARS[$session->name])) {
            $session->id = $HTTP_COOKIE_VARS[$session->name];
            $define_sid = false;
            $send_cookie = false;
        }
        if (isset($_GET[$session->name])) {
            $session->id = $_GET[$session->name];
        }
        if (isset($_POST[$session->name])) {
            $session->id = $_POST[$session->name];
        }
    }
    /*
    // Check the REQUEST_URI symbol for a string of the form
    // '<session-name>=<session-id>' to allow URLs of the form
    // http://yoursite/<session-name>=<session-id>/script.php 
        if (empty($session->id)) {
          eregi($session->name . '=([^/]+)', $GLOBALS['REQUEST_URI'], $regs);
          $regs[1] = trim($regs[1]);
          if (!empty($regs[1])) {
            $session->id = $regs[1];
          }
        }
    */
    // Check whether the current request was referred to by
    // an external site which invalidates the previously found ID
    if (!empty($session->id) && $session->referer_check) {
        $url = parse_url($GLOBALS['HTTP_REFERER']);
        if (trim($url['host']) != $GLOBALS['SERVER_NAME']) {
            unset($session->id);
            $send_cookie = true;
            $define_sid = true;
        }
    }
    // Do we have an existing session ID?
    if (empty($session->id)) {
        // Create new session ID
        $session->id = _session_create_id();
    }
    // Is use_cookies set to false?
    if (!$session->use_cookies && $send_cookie) {
        $define_sid = true;
        $send_cookie = false;
    }
    // Should we send a cookie?
    if ($send_cookie) {
        setcookie($session->name, $session->id, $session->cookie_lifetime, $session->cookie_path, $session->cookie_domain);
    }
    // Should we define the SID?
    if ($define_sid) {
        $SID = $session->name . '=' . $session->id;
    }
    $session->nr_open_sessions++;
    // Send caching headers
    // Start session
    $mod = $GLOBALS[$session->mod_name];
    if (!$mod->open($session->save_path, $session->name)) {
        die('Failed to initialize session module.');
    }
    // Read session data
    if ($val = $mod->read($session->id)) {
        // Decode session data
        session_decode($val);
    }
    // Send HTTP cache headers
    _session_cache_limiter();
    // Check if we should clean up (call the garbage collection routines)
    if ($session->gc_probability > 0) {
        $randmax = getrandmax();
        $nrand = (int) (100 * smn_rand() / $randmax);
        if ($nrand < $session->gc_probability) {
            $mod->gc($session->gc_maxlifetime);
        }
    }
    if ($define_sid) {
        define('SID', $SID);
    } else {
        define('SID', '');
    }
    return true;
}
Example #5
0
function smn_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 = smn_rand(0, 9);
        } else {
            $char = chr(smn_rand(0, 255));
        }
        if ($type == 'mixed') {
            if (eregi('^[a-z0-9]$', $char)) {
                $rand_value .= $char;
            }
        } elseif ($type == 'chars') {
            if (eregi('^[a-z]$', $char)) {
                $rand_value .= $char;
            }
        } elseif ($type == 'digits') {
            if (ereg('^[0-9]$', $char)) {
                $rand_value .= $char;
            }
        }
    }
    return $rand_value;
}