diff --git a/config/captcha.php b/config/captcha.php index 421676e..42a806e 100644 --- a/config/captcha.php +++ b/config/captcha.php @@ -2,7 +2,7 @@ return [ - 'characters' => '2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ', + 'characters' => ['2','3','4','6','7','8','9','a','b','c','d','e','f','g','h','j','m','n','p','q','r','t','u','x','y','z','A','B','C','D','E','F','G','H','J','M','N','P','Q','R','T','U','X','Y','Z'], 'default' => [ 'length' => 9, diff --git a/src/Captcha.php b/src/Captcha.php index 21e3888..4deb6a3 100644 --- a/src/Captcha.php +++ b/src/Captcha.php @@ -117,7 +117,7 @@ class Captcha protected $characters; /** - * @var string + * @var array */ protected $text; @@ -198,7 +198,7 @@ public function __construct( $this->session = $session; $this->hasher = $hasher; $this->str = $str; - $this->characters = config('captcha.characters','2346789abcdefghjmnpqrtuxyzABCDEFGHJMNPQRTUXYZ'); + $this->characters = config('captcha.characters',['1','2','3','4','6','7','8','9']); } /** @@ -306,9 +306,9 @@ protected function background() */ protected function generate() { - $characters = str_split($this->characters); + $characters = is_string($this->characters) ? str_split($this->characters) : $this->characters; - $bag = ''; + $bag = []; $key = ''; if ($this->math) { @@ -319,9 +319,10 @@ protected function generate() $key .= ''; } else { for ($i = 0; $i < $this->length; $i++) { - $bag .= $characters[rand(0, count($characters) - 1)]; + $char = $characters[rand(0, count($characters) - 1)]; + $bag[] = $this->sensitive ? $char : $this->str->lower($char); } - $key = $this->sensitive ? $bag : $this->str->lower($bag); + $key = implode('', $bag); } $hash = $this->hasher->make($key); @@ -342,24 +343,24 @@ protected function generate() */ protected function text() { - $marginTop = $this->image->height() / $this->length; - - $i = 0; - foreach(str_split($this->text) as $char) - { - $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); - - $this->image->text($char, $marginLeft, $marginTop, function($font) { - $font->file($this->font()); - $font->size($this->fontSize()); - $font->color($this->fontColor()); - $font->align('left'); - $font->valign('top'); - $font->angle($this->angle()); - }); - - $i++; - } + $marginTop = $this->image->height() / $this->length; + + $i = 0; + foreach($this->text as $char) + { + $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); + + $this->image->text($char, $marginLeft, $marginTop, function($font) { + $font->file($this->font()); + $font->size($this->fontSize()); + $font->color($this->fontColor()); + $font->align('left'); + $font->valign('top'); + $font->angle($this->angle()); + }); + + $i++; + } } /**