@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | } |
278 | 278 | |
279 | 279 | return $api ? [ |
280 | - 'sensitive' => $generator['sensitive'], |
|
281 | - 'key' => $generator['key'], |
|
282 | - 'img' => $this->image->encode('data-url')->encoded |
|
280 | + 'sensitive' => $generator['sensitive'], |
|
281 | + 'key' => $generator['key'], |
|
282 | + 'img' => $this->image->encode('data-url')->encoded |
|
283 | 283 | ] : $this->image->response('png', $this->quality); |
284 | 284 | } |
285 | 285 | |
@@ -300,24 +300,24 @@ discard block |
||
300 | 300 | */ |
301 | 301 | protected function generate() |
302 | 302 | { |
303 | - $bag = []; |
|
304 | - for($i = 0; $i < $this->length; $i++) |
|
305 | - { |
|
306 | - $char = $this->characters[rand(0, count($this->characters) - 1)]; |
|
307 | - $bag[] = $this->sensitive ? $char : $this->str->lower($char); |
|
308 | - } |
|
309 | - |
|
310 | - $hash = $this->hasher->make(implode('', $bag)); |
|
311 | - $this->session->put('captcha', [ |
|
312 | - 'sensitive' => $this->sensitive, |
|
313 | - 'key' => $hash |
|
314 | - ]); |
|
315 | - |
|
316 | - return [ |
|
317 | - 'value' => $bag, |
|
318 | - 'sensitive' => $this->sensitive, |
|
319 | - 'key' => $hash |
|
320 | - ]; |
|
303 | + $bag = []; |
|
304 | + for($i = 0; $i < $this->length; $i++) |
|
305 | + { |
|
306 | + $char = $this->characters[rand(0, count($this->characters) - 1)]; |
|
307 | + $bag[] = $this->sensitive ? $char : $this->str->lower($char); |
|
308 | + } |
|
309 | + |
|
310 | + $hash = $this->hasher->make(implode('', $bag)); |
|
311 | + $this->session->put('captcha', [ |
|
312 | + 'sensitive' => $this->sensitive, |
|
313 | + 'key' => $hash |
|
314 | + ]); |
|
315 | + |
|
316 | + return [ |
|
317 | + 'value' => $bag, |
|
318 | + 'sensitive' => $this->sensitive, |
|
319 | + 'key' => $hash |
|
320 | + ]; |
|
321 | 321 | } |
322 | 322 | |
323 | 323 | /** |
@@ -325,24 +325,24 @@ discard block |
||
325 | 325 | */ |
326 | 326 | protected function text() |
327 | 327 | { |
328 | - $marginTop = $this->image->height() / $this->length; |
|
329 | - |
|
330 | - $i = 0; |
|
331 | - foreach($this->text as $char) |
|
332 | - { |
|
333 | - $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
334 | - |
|
335 | - $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
336 | - $font->file($this->font()); |
|
337 | - $font->size($this->fontSize()); |
|
338 | - $font->color($this->fontColor()); |
|
339 | - $font->align('left'); |
|
340 | - $font->valign('top'); |
|
341 | - $font->angle($this->angle()); |
|
342 | - }); |
|
343 | - |
|
344 | - $i++; |
|
345 | - } |
|
328 | + $marginTop = $this->image->height() / $this->length; |
|
329 | + |
|
330 | + $i = 0; |
|
331 | + foreach($this->text as $char) |
|
332 | + { |
|
333 | + $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
334 | + |
|
335 | + $this->image->text($char, $marginLeft, $marginTop, function($font) { |
|
336 | + $font->file($this->font()); |
|
337 | + $font->size($this->fontSize()); |
|
338 | + $font->color($this->fontColor()); |
|
339 | + $font->align('left'); |
|
340 | + $font->valign('top'); |
|
341 | + $font->angle($this->angle()); |
|
342 | + }); |
|
343 | + |
|
344 | + $i++; |
|
345 | + } |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | /** |
@@ -416,42 +416,42 @@ discard block |
||
416 | 416 | return $this->image; |
417 | 417 | } |
418 | 418 | |
419 | - /** |
|
420 | - * Captcha check |
|
421 | - * |
|
422 | - * @param $value |
|
423 | - * @return bool |
|
424 | - */ |
|
425 | - public function check($value) |
|
426 | - { |
|
427 | - if ( ! $this->session->has('captcha')) |
|
428 | - { |
|
429 | - return false; |
|
430 | - } |
|
431 | - |
|
432 | - $key = $this->session->get('captcha.key'); |
|
433 | - $sensitive = $this->session->get('captcha.sensitive'); |
|
434 | - |
|
435 | - if ( ! $sensitive) |
|
436 | - { |
|
437 | - $value = $this->str->lower($value); |
|
438 | - } |
|
439 | - |
|
440 | - $this->session->remove('captcha'); |
|
441 | - |
|
442 | - return $this->hasher->check($value, $key); |
|
443 | - } |
|
444 | - |
|
445 | - /** |
|
446 | - * Captcha check |
|
447 | - * |
|
448 | - * @param $value |
|
449 | - * @return bool |
|
450 | - */ |
|
451 | - public function check_api($value, $key) |
|
452 | - { |
|
453 | - return $this->hasher->check($value, $key); |
|
454 | - } |
|
419 | + /** |
|
420 | + * Captcha check |
|
421 | + * |
|
422 | + * @param $value |
|
423 | + * @return bool |
|
424 | + */ |
|
425 | + public function check($value) |
|
426 | + { |
|
427 | + if ( ! $this->session->has('captcha')) |
|
428 | + { |
|
429 | + return false; |
|
430 | + } |
|
431 | + |
|
432 | + $key = $this->session->get('captcha.key'); |
|
433 | + $sensitive = $this->session->get('captcha.sensitive'); |
|
434 | + |
|
435 | + if ( ! $sensitive) |
|
436 | + { |
|
437 | + $value = $this->str->lower($value); |
|
438 | + } |
|
439 | + |
|
440 | + $this->session->remove('captcha'); |
|
441 | + |
|
442 | + return $this->hasher->check($value, $key); |
|
443 | + } |
|
444 | + |
|
445 | + /** |
|
446 | + * Captcha check |
|
447 | + * |
|
448 | + * @param $value |
|
449 | + * @return bool |
|
450 | + */ |
|
451 | + public function check_api($value, $key) |
|
452 | + { |
|
453 | + return $this->hasher->check($value, $key); |
|
454 | + } |
|
455 | 455 | |
456 | 456 | /** |
457 | 457 | * Generate captcha image source |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | $this->session = $session; |
193 | 193 | $this->hasher = $hasher; |
194 | 194 | $this->str = $str; |
195 | - $this->characters = config('captcha.characters',[]); |
|
195 | + $this->characters = config('captcha.characters', []); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | /** |
@@ -201,9 +201,9 @@ discard block |
||
201 | 201 | */ |
202 | 202 | protected function configure($config) |
203 | 203 | { |
204 | - if ($this->config->has('captcha.' . $config)) |
|
204 | + if ($this->config->has('captcha.'.$config)) |
|
205 | 205 | { |
206 | - foreach($this->config->get('captcha.' . $config) as $key => $val) |
|
206 | + foreach ($this->config->get('captcha.'.$config) as $key => $val) |
|
207 | 207 | { |
208 | 208 | $this->{$key} = $val; |
209 | 209 | } |
@@ -219,10 +219,10 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function create($config = 'default', $api = false) |
221 | 221 | { |
222 | - $this->backgrounds = $this->files->files(__DIR__ . '/../assets/backgrounds'); |
|
223 | - $this->fonts = $this->files->files(__DIR__ . '/../assets/fonts'); |
|
222 | + $this->backgrounds = $this->files->files(__DIR__.'/../assets/backgrounds'); |
|
223 | + $this->fonts = $this->files->files(__DIR__.'/../assets/fonts'); |
|
224 | 224 | |
225 | - if (app()->version() >= 5.5){ |
|
225 | + if (app()->version() >= 5.5) { |
|
226 | 226 | $this->fonts = array_map(function($file) { |
227 | 227 | return $file->getPathName(); |
228 | 228 | }, $this->fonts); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | protected function generate() |
302 | 302 | { |
303 | 303 | $bag = []; |
304 | - for($i = 0; $i < $this->length; $i++) |
|
304 | + for ($i = 0; $i < $this->length; $i++) |
|
305 | 305 | { |
306 | 306 | $char = $this->characters[rand(0, count($this->characters) - 1)]; |
307 | 307 | $bag[] = $this->sensitive ? $char : $this->str->lower($char); |
@@ -328,9 +328,9 @@ discard block |
||
328 | 328 | $marginTop = $this->image->height() / $this->length; |
329 | 329 | |
330 | 330 | $i = 0; |
331 | - foreach($this->text as $char) |
|
331 | + foreach ($this->text as $char) |
|
332 | 332 | { |
333 | - $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
333 | + $marginLeft = $this->textLeftPadding + ($i * ($this->image->width() - $this->textLeftPadding) / $this->length); |
|
334 | 334 | |
335 | 335 | $this->image->text($char, $marginLeft, $marginTop, function($font) { |
336 | 336 | $font->file($this->font()); |
@@ -401,14 +401,14 @@ discard block |
||
401 | 401 | */ |
402 | 402 | protected function lines() |
403 | 403 | { |
404 | - for($i = 0; $i <= $this->lines; $i++) |
|
404 | + for ($i = 0; $i <= $this->lines; $i++) |
|
405 | 405 | { |
406 | 406 | $this->image->line( |
407 | 407 | rand(0, $this->image->width()) + $i * rand(0, $this->image->height()), |
408 | 408 | rand(0, $this->image->height()), |
409 | 409 | rand(0, $this->image->width()), |
410 | 410 | rand(0, $this->image->height()), |
411 | - function ($draw) { |
|
411 | + function($draw) { |
|
412 | 412 | $draw->color($this->fontColor()); |
413 | 413 | } |
414 | 414 | ); |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | */ |
462 | 462 | public function src($config = null) |
463 | 463 | { |
464 | - return url('captcha' . ($config ? '/' . $config : '/default')) . '?' . $this->str->random(8); |
|
464 | + return url('captcha'.($config ? '/'.$config : '/default')).'?'.$this->str->random(8); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /** |
@@ -475,14 +475,14 @@ discard block |
||
475 | 475 | public function img($config = null, $attrs = []) |
476 | 476 | { |
477 | 477 | $attrs_str = ''; |
478 | - foreach($attrs as $attr => $value){ |
|
479 | - if ($attr == 'src'){ |
|
478 | + foreach ($attrs as $attr => $value) { |
|
479 | + if ($attr == 'src') { |
|
480 | 480 | //Neglect src attribute |
481 | 481 | continue; |
482 | 482 | } |
483 | 483 | $attrs_str .= $attr.'="'.$value.'" '; |
484 | 484 | } |
485 | - return '<img src="' . $this->src($config) . '" '. trim($attrs_str).'>'; |
|
485 | + return '<img src="'.$this->src($config).'" '.trim($attrs_str).'>'; |
|
486 | 486 | } |
487 | 487 | |
488 | 488 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | return [ |
4 | 4 | |
5 | - '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'], |
|
5 | + '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'], |
|
6 | 6 | |
7 | 7 | 'default' => [ |
8 | 8 | 'length' => 5, |