Font
3 years ago
CaptchaBuilder.php
8 months ago
CaptchaBuilderInterface.php
4 years ago
ImageFileHandler.php
4 years ago
PhraseBuilder.php
4 years ago
PhraseBuilderInterface.php
4 years ago
index.php
3 years ago
PhraseBuilder.php
41 lines
| 1 | <?php |
| 2 | namespace MailPoetVendor\Gregwar\Captcha; |
| 3 | if (!defined('ABSPATH')) exit; |
| 4 | class PhraseBuilder implements PhraseBuilderInterface |
| 5 | { |
| 6 | public $length; |
| 7 | public $charset; |
| 8 | public function __construct($length = 5, $charset = 'abcdefghijklmnpqrstuvwxyz123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ') |
| 9 | { |
| 10 | $this->length = $length; |
| 11 | $this->charset = $charset; |
| 12 | } |
| 13 | public function build($length = null, $charset = null) |
| 14 | { |
| 15 | if ($length !== null) { |
| 16 | $this->length = $length; |
| 17 | } |
| 18 | if ($charset !== null) { |
| 19 | $this->charset = $charset; |
| 20 | } |
| 21 | $phrase = ''; |
| 22 | $chars = \str_split($this->charset); |
| 23 | for ($i = 0; $i < $this->length; $i++) { |
| 24 | $phrase .= $chars[\array_rand($chars)]; |
| 25 | } |
| 26 | return $phrase; |
| 27 | } |
| 28 | public function niceize($str) |
| 29 | { |
| 30 | return self::doNiceize($str); |
| 31 | } |
| 32 | public static function doNiceize($str) |
| 33 | { |
| 34 | return \strtr(\strtolower($str), '01', 'ol'); |
| 35 | } |
| 36 | public static function comparePhrases($str1, $str2) |
| 37 | { |
| 38 | return self::doNiceize($str1) === self::doNiceize($str2); |
| 39 | } |
| 40 | } |
| 41 |