-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
38 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
|
@@ -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; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 | ||
* | ||
*/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
|
@@ -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 | ||
* | ||
*/ | ||
|