Skip to content

Commit

Permalink
Merge branch 'master' into nextgen
Browse files Browse the repository at this point in the history
  • Loading branch information
dapphp committed May 30, 2020
2 parents e29e71d + 5fc5953 commit aabde76
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGES
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CHANGES

4.0.2
- Merge changes from 3.6.8
- Merge changes from master branch release 3.6.8

4.0.1
- Increase captcha difficulty
Expand Down
50 changes: 32 additions & 18 deletions securimage.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
* @link https://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
* @copyright 2018 Drew Phillips
* @author Drew Phillips <[email protected]>
* @version 4.0.1 (March 2018)
* @version 4.0.2 (March 2018)
* @package Securimage
*
* See the file CHANGES for changelog
Expand Down Expand Up @@ -2249,45 +2249,59 @@ protected function readCodeFromFile($numWords = 1)
if (!$fp) return false;

$fsize = filesize($this->wordlist_file);
if ($fsize < 128) return false; // too small of a list to be effective
if ($fsize < 512) return false; // too small of a list to be effective

if ((int)$numWords < 1 || (int)$numWords > 5) $numWords = 1;

$words = array();
$i = 0;
$w = 0;
$tries = 0;
do {
fseek($fp, mt_rand(0, $fsize - 128), SEEK_SET); // seek to a random position of file from 0 to filesize-128
$data = fread($fp, 128); // read a chunk from our random position
fseek($fp, mt_rand(0, $fsize - 512), SEEK_SET); // seek to a random position of file from 0 to filesize - 512 bytes
$data = fread($fp, 512); // read a chunk from our random position

if ($mb_support !== false) {
$data = mb_ereg_replace("\r?\n", "\n", $data);
} else {
$data = preg_replace("/\r?\n/", "\n", $data);
if ( ($p = $this->strpos($data, "\n")) !== false) {
$data = $this->substr($data, $p + 1);
}

if ( ($start = @$this->strpos($data, "\n", mt_rand(0, $this->strlen($data) / 2))) === false) {
continue;
}

$start = @$this->strpos($data, "\n", mt_rand(0, 56)) + 1; // random start position
$end = @$this->strpos($data, "\n", $start); // find end of word
$data = $this->substr($data,$start + 1);
$word = '';

for ($i = 0; $i < $this->strlen($data); ++$i) {
$c = $this->substr($data, $i, 1);
if ($c == "\r") continue;
if ($c == "\n") break;

if ($start === false) {
// picked start position at end of file
$word .= $c;
}

$word = trim($word);

if (empty($word)) {
continue;
} else if ($end === false) {
$end = $this->strlen($data);
}

$word = $strtolower_func($this->substr($data, $start, $end - $start)); // return a line of the file
$word = $strtolower_func($word);

if ($mb_support) {
// convert to UTF-8 for imagettftext
$word = mb_convert_encoding($word, 'UTF-8', $this->wordlist_file_encoding);
}

$words[] = $word;
} while (++$i < $numWords);
} while (++$w < $numWords && $tries++ < $numWords * 2);

fclose($fp);

if ($numWords < 2) {
if (count($words) < $numWords) {
return false;
}

if ($numWords == 1) {
return $words[0];
} else {
return $words;
Expand Down
4 changes: 2 additions & 2 deletions securimage_play.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@
* @link http://www.phpcaptcha.org Securimage PHP CAPTCHA
* @link http://www.phpcaptcha.org/latest.zip Download Latest Version
* @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
* @copyright 2012 Drew Phillips
* @copyright 2018 Drew Phillips
* @author Drew Phillips <[email protected]>
* @version 3.6.6 (Nov 20 2017)
* @version 4.0.2 (May 2020)
* @package Securimage
*
*/
Expand Down
6 changes: 3 additions & 3 deletions securimage_show.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* Project: Securimage: A PHP class for creating and managing form CAPTCHA images<br />
* File: securimage_show.php<br />
*
* Copyright (c) 2013, Drew Phillips
* Copyright (c) 2018, Drew Phillips
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
Expand Down Expand Up @@ -37,9 +37,9 @@
* @link http://www.phpcaptcha.org Securimage PHP CAPTCHA
* @link http://www.phpcaptcha.org/latest.zip Download Latest Version
* @link http://www.phpcaptcha.org/Securimage_Docs/ Online Documentation
* @copyright 2013 Drew Phillips
* @copyright 2018 Drew Phillips
* @author Drew Phillips <[email protected]>
* @version 3.6.6 (Nov 20 2017)
* @version 4.0.2 (May 2020)
* @package Securimage
*
*/
Expand Down

0 comments on commit aabde76

Please sign in to comment.