Skip to content

Commit

Permalink
Bug fixed and typo
Browse files Browse the repository at this point in the history
Case sensitive bug fixed -
mewebstudio#46
Typo fixed
  • Loading branch information
mewebstudio committed Sep 3, 2015
1 parent f6595ac commit e11676b
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 21 deletions.
73 changes: 57 additions & 16 deletions src/Captcha.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
<?php namespace Mews\Captcha;
<?php

namespace Mews\Captcha;

/**
*
* Laravel 5 Captcha package
*
* @copyright Copyright (c) 2015 MeWebStudio
* @version 2.0.0
* @version 2.x
* @author Muharrem ERİN
* @contact [email protected]
* @web http://www.mewebstudio.com
* @date 2015-04-03
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
*
*/

use Exception;
Expand All @@ -21,6 +22,10 @@
use Intervention\Image\ImageManager;
use Illuminate\Session\Store as Session;

/**
* Class Captcha
* @package Mews\Captcha
*/
class Captcha
{

Expand Down Expand Up @@ -166,7 +171,14 @@ class Captcha
* @throws Exception
* @internal param Validator $validator
*/
public function __construct(Filesystem $files, Repository $config, ImageManager $imageManager, Session $session, Hasher $hasher, Str $str)
public function __construct(
Filesystem $files,
Repository $config,
ImageManager $imageManager,
Session $session,
Hasher $hasher,
Str $str
)
{
$this->files = $files;
$this->config = $config;
Expand All @@ -192,6 +204,8 @@ protected function configure($config)
}

/**
* Create captcha image
*
* @param string $config
* @return ImageManager->response
*/
Expand Down Expand Up @@ -250,6 +264,8 @@ public function create($config = 'default')
}

/**
* Image backgrounds
*
* @return string
*/
protected function background()
Expand All @@ -258,29 +274,30 @@ protected function background()
}

/**
* Generate captcha text
*
* @return string
*/
protected function generate()
{
$characters = str_split($this->characters);

$bag = '';
for($i = 0; $i < $this->length; $i++)
{
$bag .= $characters[rand(0, count($characters) - 1)];
}

if ( ! $this->sensitive)
{
$bag = $this->str->lower($bag);
}

$this->session->put('captcha', $this->hasher->make($bag));
$this->session->put('captcha', [
'sensitive' => $this->sensitive,
'key' => $this->hasher->make($this->sensitive ? $bag : $this->str->lower($bag))
]);

return $bag;
}

/**
* Writing text
* Writing captcha text
*/
protected function text()
{
Expand All @@ -305,6 +322,8 @@ protected function text()
}

/**
* Image fonts
*
* @return string
*/
protected function font()
Expand All @@ -313,6 +332,8 @@ protected function font()
}

/**
* Random font size
*
* @return integer
*/
protected function fontSize()
Expand All @@ -321,6 +342,8 @@ protected function fontSize()
}

/**
* Random font color
*
* @return array
*/
protected function fontColor()
Expand All @@ -338,6 +361,8 @@ protected function fontColor()
}

/**
* Angle
*
* @return int
*/
protected function angle()
Expand All @@ -346,6 +371,8 @@ protected function angle()
}

/**
* Random image lines
*
* @return \Intervention\Image\Image
*/
protected function lines()
Expand All @@ -366,21 +393,33 @@ function ($draw) {
}

/**
* Captcha check
*
* @param $value
* @return bool
*/
public function check($value)
{
$store = $this->session->get('captcha');
if ($this->sensitive)
if ( ! $this->session->has('captcha'))
{
return false;
}

$key = $this->session->get('captcha.key');

if ( ! $this->session->get('captcha.sensitive'))
{
$value = $this->str->lower($value);
$store = $this->str->lower($store);
}
return $this->hasher->check($value, $store);

$this->session->remove('captcha');

return $this->hasher->check($value, $key);
}

/**
* Generate captcha image source
*
* @param null $config
* @return string
*/
Expand All @@ -390,6 +429,8 @@ public function src($config = null)
}

/**
* Generate captcha image html tag
*
* @param null $config
* @return string
*/
Expand Down
6 changes: 5 additions & 1 deletion src/CaptchaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

use Illuminate\Routing\Controller;

/**
* Class CaptchaController
* @package Mews\Captcha
*/
class CaptchaController extends Controller
{

Expand All @@ -12,7 +16,7 @@ class CaptchaController extends Controller
*
* @param \Mews\Captcha\Captcha $captcha
* @param string $config
* @return ImageManager->response
* @return \Intervention\Image\ImageManager->response
*/
public function getCaptcha(Captcha $captcha, $config = 'default')
{
Expand Down
8 changes: 7 additions & 1 deletion src/CaptchaServiceProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?php namespace Mews\Captcha;
<?php

namespace Mews\Captcha;

use Illuminate\Support\ServiceProvider;

/**
* Class CaptchaServiceProvider
* @package Mews\Captcha
*/
class CaptchaServiceProvider extends ServiceProvider {

/**
Expand Down
7 changes: 6 additions & 1 deletion src/Facades/Captcha.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php namespace Mews\Captcha\Facades;
<?php

namespace Mews\Captcha\Facades;

use Illuminate\Support\Facades\Facade;

Expand All @@ -7,6 +9,9 @@
*/
class Captcha extends Facade {

/**
* @return string
*/
protected static function getFacadeAccessor() { return 'captcha'; }

}
18 changes: 16 additions & 2 deletions src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,21 @@

if ( ! function_exists('captcha')) {

/**
* @param string $config
* @return mixed
*/
function captcha($config = 'default')
{
return app('captcha')->create($config);
}
}

if ( ! function_exists('captcha_src')) {

/**
* @param string $config
* @return string
*/
function captcha_src($config = 'default')
{
return app('captcha')->src($config);
Expand All @@ -18,6 +25,10 @@ function captcha_src($config = 'default')

if ( ! function_exists('captcha_img')) {

/**
* @param string $config
* @return mixed
*/
function captcha_img($config = 'default')
{
return app('captcha')->img($config);
Expand All @@ -26,7 +37,10 @@ function captcha_img($config = 'default')


if ( ! function_exists('captcha_check')) {

/**
* @param $value
* @return bool
*/
function captcha_check($value)
{
return app('captcha')->check($value);
Expand Down

0 comments on commit e11676b

Please sign in to comment.