Ignore:
Timestamp:
07/29/10 17:16:11 (22 months ago)
Author:
root
Message:

merged trunk into branches PLi-Fusion and ITXP

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PLi-Fusion/includes/secureimage-1.0.3/securimage.php

    r1986 r2364  
    1818 * License along with this library; if not, write to the Free Software 
    1919 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA<br /><br /> 
    20  *  
    21  * Any modifications to the library should be indicated clearly in the source code  
     20 * 
     21 * Any modifications to the library should be indicated clearly in the source code 
    2222 * to inform users that the changes are not a part of the original software.<br /><br /> 
    2323 * 
     
    121121  var $charset = 'ABCDEFGHKLMNPRSTUVWYZ23456789'; 
    122122  //var $charset = '0123456789'; 
    123    
     123 
    124124  /** 
    125125   * Create codes using this word list 
     
    128128   */ 
    129129  var $wordlist_file = ''; 
    130    
     130 
    131131  /** 
    132132   * True to use a word list file instead of a random code 
     
    363363  var $audio_path = './audio/'; 
    364364 
     365  /** 
     366   * Captcha expiry timeout in seconds. 
     367   * 
     368   * @since 1.0.3 
     369   * @var string 
     370   */ 
     371  var $timeout = 300; 
     372 
     373 
    365374 
    366375  //END USER CONFIGURATION 
     
    423432      die('no session available!'); 
    424433    } 
    425      
     434 
    426435    // we use random colors to make it even more difficult 
    427436    $this->image_bg_color = $this->getHexColor(); 
     
    445454    return $clr; 
    446455  } 
    447     
     456 
    448457  /** 
    449458   * Generate a code and output the image to the browser. 
     
    693702  { 
    694703    $this->code = false; 
    695      
     704 
    696705    if ($this->use_wordlist && is_readable($this->wordlist_file)) { 
    697706      $this->code = $this->readCodeFromFile(); 
    698707    } 
    699      
     708 
    700709    if ($this->code == false) { 
    701710      $this->code = $this->generateCode($this->code_length); 
    702711    } 
    703      
     712 
    704713    $this->saveData(); 
    705714  } 
     
    721730    return $code; 
    722731  } 
    723    
     732 
    724733  /** 
    725734   * Reads a word list file to get a code 
     
    733742    $fp = @fopen($this->wordlist_file, 'r'); 
    734743    if (!$fp) return false; 
    735      
     744 
    736745    $fsize = filesize($this->wordlist_file); 
    737746    if ($fsize < 32) return false; // too small of a list to be effective 
    738      
     747 
    739748    if ($fsize < 128) { 
    740749      $max = $fsize; // still pretty small but changes the range of seeking 
     
    742751      $max = 128; 
    743752    } 
    744      
     753 
    745754    fseek($fp, rand(0, $fsize - $max), SEEK_SET); 
    746755    $data = fread($fp, 128); // read a random 128 bytes from file 
    747756    fclose($fp); 
    748      
     757 
    749758    $start = strpos($data, "\n", rand(0, 100)) + 1; // random start position 
    750759    $end   = strpos($data, "\n", $start) - 1; // find end of word 
    751      
     760 
    752761    return strtolower(substr($data, $start, $end - $start)); // return substring in 128 bytes 
    753762  } 
     
    822831  { 
    823832    $_SESSION['securimage_code_value'] = strtolower($this->code); 
     833    $_SESSION['securimage_code_timestamp'] = time(); 
    824834  } 
    825835 
     
    834844    if ( isset($_SESSION['securimage_code_value']) && !empty($_SESSION['securimage_code_value']) ) { 
    835845      if ( $_SESSION['securimage_code_value'] == strtolower(trim($this->code_entered)) ) { 
    836         $this->correct_code = true; 
    837         $_SESSION['securimage_code_value'] = ''; 
     846        if (isset($_SESSION['securimage_code_timestamp']) && (time() - $_SESSION['securimage_code_timestamp']) < $this->timeout) { 
     847          $this->correct_code = true; 
     848          $_SESSION['securimage_code_value'] = ''; 
     849        } else { 
     850          $this->correct_code = false; 
     851        } 
    838852      } else { 
    839853        $this->correct_code = false; 
     
    906920      $file['size']            = $data['ChunkSize'] + 8; 
    907921      $file['data']            = $body; 
    908        
     922 
    909923      if ( ($p = strpos($file['data'], 'LIST')) !== false) { 
    910924        // If the LIST data is not at the end of the file, this will probably break your sound file 
     
    914928        $file['size'] = $file['size'] - (strlen($file['data']) - $p); 
    915929      } 
    916        
     930 
    917931      $files[] = $file; 
    918932      $data    = null; 
Note: See TracChangeset for help on using the changeset viewer.